home *** CD-ROM | disk | FTP | other *** search
- /*
-
- mapper.c 3/15/89
- updated 12/14/90
-
- mpp1.bat = cl /AL mapper.c vmaputil vimage2 dispio paradise
-
- by Russell A. Ambroziak, Ph. D.
-
- command line options:
-
- /e = EGA
- /v = VGA 640x480x16 colors
- /s = VGA 320x200x256 colors
- /y = Extended VGA 640x400x256 colors
- /x = Extended VGA 640x480x256 colors
-
- /l [path][file_name].[file_type] = output '.LAB' file of points
- /o [path][file_name].[file_type] = output run information file
- /a [path][file_name] = automatic map load on start
- /p [program_name] = passes control to program from point (S)earch
-
- */
- #include <conio.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include "font.h"
- #include <process.h>
- #include <stdlib.h>
- #include <errno.h>
-
- #define VGA 0
- /*#define NUMBER9 9*/
- #define MAX_X 640
- /*#define MAX_X 1024*/
- #define MENUXC 550
- /*#define MENUXC 950*/
- /*#define COREOFF 0*/
-
- #define DEG_RAD 0.01745329251 /* converts degrees to radians */
- #define MAXDO 1000
- #define MAX_COLORS 16
- #define STR_LEN 100
- #define MIN_PIX 0.000
- #define TYPE 'p'
-
- #define BLACK 0
- #define D_GREY 1
- #define L_GREY 2
- #define WHITE 3
- #define BUFF 4
- #define L_BUFF 5
- #define BROWN 6
- #define RED 7
- #define ORANGE 8
- #define YELLOW 9
- #define GREEN 10
- #define D_GREEN 11
- #define VD_GREEN 12
- #define BLUE 13
- #define D_BLUE 14
- #define MAGENTA 15
-
- #define NUM_TYPE 25
- #define NUM_SIZE 25
- #define NUM_PSIZE 3
- #define NUM_FILL 5
- #define NUM_SYM 25
-
- #define MENU_M 13
- #define MENU_L 8
- #define MENU_P 6
- #define MENU_IV 2
- #define SYM_SIZE 11
- #define NUM_DP 100
- #define B_LINES 48
-
- #define F_SIZE 20
- #define NAME_SIZE 100
- #define S_SIZE 40
- #define T_SIZE 15
- #define MAX_NUM 300
- #define NUM_IMAGE 2
-
- char *Menu_iv[MENU_IV]=
- {"zoom",
- "exit image"
- };
- struct Color
- {
- unsigned char r, g, b;
- }lutc[256],luts[256];
- int Black=0,White=191,Center=128,Num_Color=256;
- int D_Grey=46,L_Grey=191,M_Grey=128;
- struct Color Blk={ 0, 0, 0};
- struct Color D_G={ 46, 46, 46};
- struct Color M_G={127,127,127};
- struct Color L_G={191,191,191};
- struct Color Wht={255,255,255};
- unsigned char ActiveLut;
- int Img=0,Sample=1,Xc=0,Yc=0,Speed=16,Row,Col,ZoomSample=1;
- char *SubType;
- struct equipment
- {
- int printers; /* number present */
- int sprinter; /* serial printer installed? 0=no 1=yes */
- int game; /* game adapter installed? */
- int sports; /* number of serial ports */
- int dma; /* DMA chip installed? */
- int drives; /* number of disk drives */
- int video; /* video mode 1=40 color 2=80 color 3=80 B/W */
- int disk; /* any disk drives? */
- int memory; /* memory size in Kbytes */
- };
- extern struct equipment Eq;
- extern int GF_Order[MAX_NUM];
- extern char GF_String[MAX_NUM][S_SIZE];
- struct file_id
- {
- char name[S_SIZE];
- long size;
- unsigned date,time;
- };
- extern struct file_id GF_File[MAX_NUM];
- extern int Monitor;
- char DepthFile[100]={"colo.dpt"};
- float D1[MAX_NUM],D2[MAX_NUM];
- struct image_header
- {
- int row,col;
- int sample;
- int record_bytes,file_records;
- int record_col_header;
- int row_col_header;
- int header_bytes;
- int imbedded_header;
- int sample_bits;
- char infile[100],image[100],Lut[100],pal_type,label[100];
- int vga_color[256];
- struct Color lut[256],lutc[256];
- }Hdr[NUM_IMAGE];
-
- int Sym_Size=SYM_SIZE;
- char LastMap[STR_LEN],LastFile[STR_LEN],Auto=0;
- char *Exit={"exit"};
- float BackBright=1.0;
- int NumPath=1;
- char Path[NUM_DP][STR_LEN];
- char String[STR_LEN];
- char String[STR_LEN];
- int RawOn;
- int FontSize=2;
- float PixScale;
- char Suffix[20];
- FILE *FpLab;
- char VideoType='X';
- int MaxXs,MaxYs;
- char Disk_Dir[100];
- char *Menu_V[NUM_TYPE+3];
- char *Menu_P[NUM_SYM+3];
- char *Menu_M[MENU_M]=
- {
- "zoom", /* 0 */
- "overlays ON/OFF", /* 1 */
- "reset", /* 2 */
- "Change projection", /* 3 */
- "Save map", /* 4 */
- "Recall map", /* 5 */
- "cursor mode", /* 6 */
- "vector plot", /* 7 */
- "annotate", /* 8 */
- "draw lines", /* 9 */
- "graticule", /* 10 */
- "point plot", /* 11 */
- "exit"
- };
- /*
- 0 -- red
- 18 -- orange
- 34 -- yellow-orange
- 50 -- yellow
- 68 -- yellow-green
- 85 -- green
- 95 -- green-cyan
- 105 -- cyan
- 125 -- blue-cyan
- 144 -- blue
- 167 -- blue-purple
- 190 -- purple
- 206 -- magenta-purple
- 223 -- magenta
- 240 -- red-magenta
- 255 -- red
- */
- unsigned char MaxHues[256][3]=
- {
- 255, 0, 0,255, 32, 0,255, 42, 0,255, 53, 0,255, 60, 0,255, 68, 0,
- 255, 73, 0,255, 80, 0,255, 84, 0,255, 90, 0,255, 94, 0,255,100, 0,
- 255,103, 0,255,108, 0,255,112, 0,255,116, 0,255,121, 0,255,124, 0,
- 255,128, 0,255,132, 0,255,135, 0,255,139, 0,255,143, 0,255,146, 0,
- 255,150, 0,255,154, 0,255,157, 0,255,161, 0,255,164, 0,255,168, 0,
- 255,172, 0,255,176, 0,255,179, 0,255,183, 0,255,186, 0,255,190, 0,
- 255,194, 0,255,198, 0,255,202, 0,255,206, 0,255,210, 0,255,214, 0,
- 255,218, 0,255,222, 0,255,227, 0,255,231, 0,255,236, 0,255,241, 0,
- 255,245, 0,255,250, 0,254,255, 0,249,255, 0,244,255, 0,240,255, 0,
- 234,255, 0,229,255, 0,224,255, 0,220,255, 0,214,255, 0,209,255, 0,
- 204,255, 0,199,255, 0,194,255, 0,190,255, 0,184,255, 0,179,255, 0,
- 174,255, 0,169,255, 0,164,255, 0,158,255, 0,152,255, 0,147,255, 0,
- 141,255, 0,135,255, 0,130,255, 0,123,255, 0,116,255, 0,109,255, 0,
- 102,255, 0, 94,255, 0, 87,255, 0, 78,255, 0, 68,255, 0, 58,255, 0,
- 42,255, 0, 23,255, 0, 0,255, 36, 0,255, 58, 0,255, 73, 0,255, 87,
- 0,255,101, 0,255,113, 0,255,125, 0,255,135, 0,255,146, 0,255,156,
- 0,255,166, 0,255,176, 0,255,186, 0,255,196, 0,255,204, 0,255,214,
- 0,255,224, 0,255,233, 0,255,243, 0,255,252, 0,248,255, 0,239,255,
- 0,230,255, 0,222,255, 0,214,255, 0,207,255, 0,200,255, 0,194,255,
- 0,187,255, 0,181,255, 0,174,255, 0,169,255, 0,163,255, 0,157,255,
- 0,152,255, 0,146,255, 0,141,255, 0,136,255, 0,131,255, 0,126,255,
- 0,121,255, 0,116,255, 0,111,255, 0,106,255, 0,101,255, 0, 96,255,
- 0, 92,255, 0, 86,255, 0, 81,255, 0, 77,255, 0, 71,255, 0, 66,255,
- 0, 60,255, 0, 53,255, 0, 48,255, 0, 39,255, 0, 32,255, 0, 23,255,
- 0, 0,255, 16, 0,255, 23, 0,255, 28, 0,255, 32, 0,255, 36, 0,255,
- 39, 0,255, 42, 0,255, 45, 0,255, 48, 0,255, 50, 0,255, 53, 0,255,
- 58, 0,255, 60, 0,255, 62, 0,255, 64, 0,255, 66, 0,255, 68, 0,255,
- 70, 0,255, 73, 0,255, 75, 0,255, 77, 0,255, 78, 0,255, 81, 0,255,
- 83, 0,255, 84, 0,255, 87, 0,255, 89, 0,255, 92, 0,255, 93, 0,255,
- 94, 0,255, 97, 0,255, 98, 0,255,101, 0,255,103, 0,255,105, 0,255,
- 107, 0,255,109, 0,255,111, 0,255,113, 0,255,115, 0,255,117, 0,255,
- 119, 0,255,122, 0,255,124, 0,255,126, 0,255,129, 0,255,131, 0,255,
- 134, 0,255,135, 0,255,138, 0,255,140, 0,255,143, 0,255,145, 0,255,
- 148, 0,255,151, 0,255,154, 0,255,156, 0,255,160, 0,255,163, 0,255,
- 166, 0,255,169, 0,255,173, 0,255,176, 0,255,179, 0,255,183, 0,255,
- 188, 0,255,192, 0,255,196, 0,255,200, 0,255,204, 0,255,209, 0,255,
- 214, 0,255,220, 0,255,225, 0,255,231, 0,255,237, 0,255,244, 0,255,
- 250, 0,255,255, 0,252,255, 0,245,255, 0,238,255, 0,231,255, 0,224,
- 255, 0,217,255, 0,210,255, 0,203,255, 0,196,255, 0,190,255, 0,183,
- 255, 0,176,255, 0,170,255, 0,163,255, 0,156,255, 0,151,255, 0,144,
- 255, 0,137,255, 0,131,255, 0,125,255, 0,118,255, 0,112,255, 0,105,
- 255, 0, 98,255, 0, 90,255, 0, 83,255, 0, 77,255, 0, 68,255, 0, 60,
- 255, 0, 50,255, 0, 42,255, 0, 28,255, 0, 23
- };
- char T_Menu_L[NUM_TYPE+3][2][50];
- char *T_Menu_P[MENU_P+3][2];
- float MaxLat,MinLat,MaxLon,MinLon;
- FILE *Fpout;
- char SaveName[100]={"mapper.out"};
- double ll[MAXDO][2];
- int todo[2][MAXDO];
- unsigned char MT_Buff[12][MAX_X],Mbuff[B_LINES][MAX_X],Buffer[MAX_X];
- long MT_Buff_size=7680,Mbuff_size=30720;
- unsigned char Inbuff[BUFSIZ],Inbuff2[BUFSIZ],Outbuff[BUFSIZ];
- int SaveVec=0,SNum=1;
- int ScreenXs,ScreenYs;
- struct board
- {
- int row,col,color;
- }B_Id;
- struct map_screen
- {
- int xc,yc,xs,ys;
- }map_pos;
- struct map_input
- {
- char *name,type;
- double indat[6];
- }miv;
- struct symbol_name
- {
- char name[50],filename[50];
- float max_pix,min_pix;
- int color;
- char on;
- char Symbol[SYM_SIZE][SYM_SIZE];
- }PlaceFile[NUM_SYM];
- struct map
- {
- int KeyPlotted;
- char Fill_Name[256][20];
- int Fill_In;
- int Fill_After;
- int Fill_Color[256][2];
- int Max_Fill;
- int Fill_Color_RGB[256][3];
- float Fill_Color_IHS[256][3];
- int Fill_Order[256];
- int Comp_Color[256];
- int Num_Fill;
- float FI_min[NUM_FILL],FI_max[NUM_FILL];
- char Fill_In_Name[NUM_FILL][STR_LEN];
- int White,Num_Color;
- int screen_xs,screen_ys;
- int Num_Type,Out;
- float Pixsize,Clat,Clon,Space;
- int Mback,Text,High,Back,Grat;
- int GratOn;
- int LatLon,Black;
- char Color_Name[MAX_COLORS][30];
- int Color_Val[MAX_COLORS][3];
- int Type;
- int Ns[NUM_TYPE];
- int Mm[NUM_TYPE];
- int NumSymbol;
- int Dummy1;
- int Dummy2;
- char Group_Name[NUM_TYPE][30];
- struct line_name
- {
- char filename[54];
- float max_pix,min_pix;
- int color;
- }MapFile[NUM_TYPE][NUM_SIZE];
- struct place_name
- {
- char *name,*filename;
- float max_pix,min_pix;
- int color;
- }PlaceFile[3][3]; /* size = 18*3*3 = 162 bytes */
- struct Color lut[256];
- }M;
-
- unsigned char getpt();
-
- int fill_in();
- int auto_fill_in();
- void pix_loc();
- int check_point();
- int purge();
- void remove_boundaries();
- void fill_voids();
- void set_lut();
- int load_miv();
- void screen_mm();
- int do_menu(char *[],int,int,int,int,int,int,int,int [128][25]);
- int t_do_menu();
- int plot_map();
- void get_corners();
- int tplot_line();
- int unplot_line();
- char Zoom();
- int convert_bin();
- int read_control();
- int get_color();
- char fsplit(char *,char *,char *,char *);
- FILE *open_to_read_binary(char *);
- FILE *open_to_write_text(char *);
- FILE *open_to_write_binary(char *);
-
- main(argc,argv)
-
- int argc;
- char *argv[];
-
- {
- int i,j,k,p;
- char ans,ans2,cfile[100],string[100];
- int mt=0,lbrite=64,nbrite=127,brite;
- int cx=256,cy=ScreenYs/2;
- int xc,yc,xs,ys,ix,iy,val,speed,isize=FontSize,color;
- float pixsize=12.0,clat=38.0,clon=-95.75,space=10.0;
- int m_num=0,plotmap=0;
- FILE *fp;
- int point=0;
-
- ix=ScreenXs/2;
- iy=ScreenYs/2;
- speed=16;
-
- for(i=0;i<argc;i++)
- {
- if(argv[i][1]==':')
- add_disk_path(argv[i]);
- if(argv[i][0]=='/'&&argv[i][1]=='a')
- {
- Auto=1;
- strcpy(LastMap,argv[i+1]);
- }
- if(argv[i][0]=='/'&&argv[i][1]=='o')
- {
- if(M.Out==0&&i<argc-1)
- {
- add_disk_path(argv[i+1]);
- Fpout=fopen(argv[i+1],"wt");
- if(Fpout)
- {
- M.Out=1;
- printf("Output file = '%s'\n",argv[i+1]);
- }
- else
- {
- printf("Could not open '%s' to write.\n\n",argv[i+1]);
- M.Out=0;
- printf("HIT ANY KEY TO CONTINUE!\n\n");
- getch();
- }
- }
- }
- if(argv[i][0]=='/'&&argv[i][1]=='l')
- {
- FpLab=fopen(argv[i+1],"wt");
- if(FpLab)
- {
- printf("Label Output file = '%s'\n",argv[i+1]);
- printf("HIT ANY KEY TO CONTINUE!\n\n");
- getch();
- }
- else
- {
- printf("Could not open '%s' to write.\n\n",argv[i+1]);
- printf("HIT ANY KEY TO CONTINUE!\n\n");
- getch();
- }
- }
- if(argv[i][0]=='/'&&(argv[i][1]=='e'||argv[i][1]=='E'))
- {
- ScreenYs=380;
- cy=ScreenYs/2;
- }
- if(argv[i][0]=='/'&&argv[i][1]=='R')
- RawOn=1;
- if(argv[i][0]=='/'&&(argv[i][1]=='X'||argv[i][1]=='x'))
- VideoType='X';
- if(argv[i][0]=='/'&&(argv[i][1]=='Y'||argv[i][1]=='y'))
- VideoType='Y';
- if(argv[i][0]=='/'&&(argv[i][1]=='E'||argv[i][1]=='e'))
- VideoType='E';
- if(argv[i][0]=='/'&&(argv[i][1]=='V'||argv[i][1]=='v'))
- VideoType='V';
- if(argv[i][0]=='/'&&(argv[i][1]=='S'||argv[i][1]=='s'))
- VideoType='S';
- if(argv[i][0]=='/'&&(argv[i][1]=='g'||argv[i][1]=='G'))
- M.GratOn=1;
- }
- xc=0;yc=0;xs=ScreenXs;ys=ScreenYs;
- video_on();
- /* use SubPaths with type of SubType for sub images */
- /* move all Path up 1 */
- for(i=NumPath;i>0;i--)
- strcpy(Path[i],Path[i-1]);
- NumPath+=1;
- /* add '?mp\' to a new set of Paths */
- for(i=1;i<NumPath;i++)
- sprintf(Path[NumPath+i-1],"%s%s\\",Path[i],SubType+1);
- NumPath+=NumPath-1;
-
- /*
- SetVideoMode(0);
- for(i=0;i<NumPath;i++)
- printf("%2d -- '%s'\n",i,Path[i]);
- exit(0);
- */
-
- M.Pixsize*=PixScale;
- pixsize=M.Pixsize;
- clat=M.Clat;
- clon=M.Clon;
- space=M.Space;
- cy=ScreenYs/2;
- SetVideoMode(0);
- if(Auto==1&&strlen(LastMap)>0)
- {
- video_on();
- strcat(LastMap,Suffix);
- if(unsave_map(LastMap)>0)
- {
- plotmap=1;
- ix=ScreenXs/2;
- iy=ScreenYs/2;
- speed=16;
- m_num=6;
- pix_loc(ix,iy,&ix,&iy,&speed);
- }
- else
- SetVideoMode(0);
- }
- if(plotmap==0)
- {
- printf(" Choose a map to start with\n");
- printf("by using the up and down arrow\n");
- printf("keys, 'Pg Up' or 'Pg Dn' keys,\n");
- printf("or by typing the name of the\n");
- printf("map. Hit 'Enter' to select a\n");
- printf("map. If the map is not in this\n");
- printf("directory and you have entered\n");
- printf("command line path names, hit\n");
- printf("'Esc' to continue on to other\n");
- printf("paths.\n\n");
- printf(" If you wish to draw a map\n");
- printf("rather than load one that is\n");
- printf("already drawn -- hit 'Esc'\n");
- printf("until the menu contains '*.map'\n");
- printf("files.\n\n");
- printf(" If you copy drawn map\n");
- printf("files from one disc to another,\n");
- printf("the path names may be incorrect\n");
- printf("and you may not be able to\n");
- printf("zoom.\n");
- plotmap=0;
- sprintf(string,"*%s",Suffix);
- if(search_list(string,cfile)>=0)
- {
- video_on();
- unsave_map(cfile);
- plotmap=1;
- }
- }
- if(plotmap==0)
- {
- if(search_list("*.map",cfile)<0)
- {
- printf("No maps chosen.\n\n");
- exit(0);
- }
- if(strlen(cfile)>0)
- val=read_control(cfile);
- else
- exit(0);
- if(val<0)
- {
- if(val==-1)
- printf("Could not open control file '%s'\n\n",cfile);
- if(val==-2)
- printf("Could not find 'begin_color in file '%s'\n\n",cfile);
- if(val==-3)
- printf("Could not find 'begin_vector in file '%s'\n\n",cfile);
- if(val==-4)
- printf("Too many vectors in a group in file '%s'\n\n",cfile);
- if(val==-5)
- printf("Bad color name in file '%s'\n\n",cfile);
- if(val==-6)
- printf
- ("Missing or bad pixel size, central lat and lon or graticule spacing\n");
- exit(0);
- }
- video_on();
- M.Pixsize*=PixScale;
- pixsize=M.Pixsize;
- clat=M.Clat;
- clon=M.Clon;
- space=M.Space;
- cy=ScreenYs/2;
- set_lut('c',0);
- plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
- }
- do
- {
- m_num=M_do_menu(Menu_M,MENU_M,MENUXC,25,m_num,M.Mback,M.Text,M.High,Font);
- if(m_num==0)
- {
- pixsize=M.Pixsize;
- clat=M.Clat;
- clon=M.Clon;
- space=M.Space;
- ans=Zoom(xc,yc,ScreenXs,ScreenYs,&pixsize,&clat,&clon,&space);
- if(ans!=27)
- plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
- }
- if(m_num==1)
- {
- pixsize=M.Pixsize;
- clat=M.Clat;
- clon=M.Clon;
- space=M.Space;
- T_do_menu(T_Menu_L,M.Num_Type+3,25,25,m_num,M.Mback,M.Text,M.High,
- Font,M.Mm);
- plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
- }
- if(m_num==2)
- {
- xc=0;yc=0;xs=ScreenXs;ys=ScreenYs;
- pixsize=M.Pixsize;
- clat=M.Clat;
- clon=M.Clon;
- space=M.Space;
- plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
- }
- if(m_num==3)
- {
- pixsize=M.Pixsize;
- clat=M.Clat;
- clon=M.Clon;
- space=M.Space;
- save_box(0,M.Black,Mbuff,0,MaxYs-40,MaxXs,40);
- sprintf(String,"Give new projection type. l=Lambert a=Albers");
- if(VideoType=='S')
- plot_font_h(M.White,5,MaxYs-38,String,3,Font);
- else
- plot_font_h(M.White,5,MaxYs-38,String,2,Font);
- sprintf(String,
- "'m'=Mercator 's'=polar stereographic 'p'=plate carre S=sinusoidal");
- if(VideoType=='S')
- plot_font_h(M.White,5,MaxYs-18,String,3,Font);
- else
- plot_font_h(M.White,5,MaxYs-18,String,2,Font);
- M.Type=getch();
- if(M.Type=='l'||M.Type=='a'||
- M.Type=='m'||M.Type=='s'||M.Type=='p'||M.Type=='S')
- plot_map(xc,yc,ScreenXs,ScreenYs,pixsize,clat,clon,space,0);
- else
- {
- M.Type='p';
- unsave_box(0,M.Black,Mbuff,0,MaxYs-40,MaxXs,40);
- }
- }
- if(m_num==4)
- {
- i=0;
- do
- {
- fclose(fp);
- sprintf(string,"mapper%02d%s",i++,Suffix);
- fp=open_to_read_binary(string);
- }while(fp);
- fclose(fp);
- save_map(string);
- }
- if(m_num==5)
- {
- sprintf(string,"*%s",Suffix);
- SetVideoMode(0);
- if(search_list(string,cfile)>=0)
- {
- video_on();
- unsave_map(cfile);
- }
- else
- {
- printf("No maps chosen.\n\n");
- exit(0);
- }
- }
- if(m_num==6)
- {
- ix=ScreenXs/2;
- iy=ScreenYs/2;
- speed=16;
- pix_loc(ix,iy,&ix,&iy,&speed);
- }
- if(m_num==7)
- {
- pixsize=M.Pixsize;
- vector_plot(pixsize);
- }
- if(m_num==8)
- {
- ix=ScreenXs/2;
- iy=ScreenYs/2;
- isize=FontSize;
- color=M.White;
- while(annotate(&ix,&iy,&isize,&color)!=27);
- }
- if(m_num==9)
- {
- ix=ScreenXs/2;
- iy=ScreenYs/2;
- color=M.White;
- while(draw_line(&ix,&iy,&color)!=27);
- }
- if(m_num==10)
- add_graticule();
- if(m_num==11)
- point=point_plot(M.Pixsize,point);
- }while(m_num!=MENU_M-1);
-
- SetVideoMode(0);
- fclose(Fpout);
- fclose(FpLab);
- }
-
- /********************************************************************
- **
- ** locate a point
- **
- ********************************************************************* */
-
- void pix_loc(fx,fy,px,py,sp)
-
- int fx,fy; /* starting point of cursor */
- int *px,*py,*sp; /* pointers to final location */
-
- {
- int i,j,l,m,p;
- int ans,size=0,speed,x,y,xo,yo,k,ans2,ans3,screen_xs=ScreenXs;
- static unsigned char tbuff[200];
- int lsize=FontSize,val,ival,val1,val2;
- char string[100],pth[STR_LEN],nam[10],typ[10];
- int idc[2],clr,num;
- double lat,lon;
- FILE *fpblb;
- double dx,dy;
- int ix,iy,color=M.White,xc,txs,cspeed=8,tcolor[3];
- float fspeed=0.05;
- float pixsize=M.Pixsize;
- long lxs,lys,buffersize=(long)B_LINES*(long)MAX_X;
-
- if(VideoType=='S')
- lsize=3;
- ScreenXs=MaxXs;
- speed=*sp;
- size=0;
- xo=x=fx;
- yo=y=fy;
- tcursor(0,x,y,5,tbuff);
- lxs=42*15/lsize;
- lys=32/lsize;
- if(lxs*lys>buffersize)
- {
- printf("Box 1 too large in 'pix_loc()'\n");
- exit(0);
- }
- lxs=MaxXs;
- lys=32/lsize;
- if(lxs*lys>buffersize)
- {
- printf("Box 2 too large in 'pix_loc()'\n");
- exit(0);
- }
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- while((ans=getpad(&size,&x,&y,&speed,0))!=27&&ans!=13)
- {
- if(ans=='h'||ans=='H'||ans==59) /* F1 */
- {
- txs=ScreenXs;
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- save_box(0,M.Back,Mbuff,
- 0,0,MaxXs,32/lsize);
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
- {
- sprintf(string,
- "(k)ey (K)ey (n)ame 1 (N)ame all (P)aint area (R)emove lines");
- plot_font_h(M.White,1,1,string,FontSize,Font);
- if(getch()==0)
- getch();
- if(M.Fill_In>0)
- {
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- sprintf(string,"(D)arker map colors (B)righter map colors");
- plot_font_h(M.White,1,1,string,FontSize,Font);
- if(getch()==0)
- getch();
- }
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- sprintf(string,
- "(E)dit colors (C)olor table output (f)lash");
- }
- else
- sprintf(string,
- "(k)ey (K)ey (n)ame 1 (N)ame all (P)aint area");
- plot_font_h(M.White,1,1,string,FontSize,Font);
- if(getch()==0)
- getch();
- if(M.NumSymbol>0)
- {
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- #ifdef COREOFF
- sprintf(string,"(i)ndex points");
- #else
- sprintf(string,"(l)abel points (i)ndex points");
- #endif
- plot_font_h(M.White,1,1,string,FontSize,Font);
- getch();
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- sprintf(string,"(S)earch for nearest point e(x)it to picture");
- plot_font_h(M.White,1,1,string,FontSize,Font);
- getch();
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- }
- unsave_box(0,M.Back,Mbuff,
- 0,0,MaxXs,32/lsize);
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- screen_xs=txs;
- }
- uncursor(0,xo,yo,5,tbuff);
- val=getpt(0,x,y)-16;
- color=M.Comp_Color[val+16];
- tcursor(0,x,y,5,tbuff);
- cursor(0,x,y,color,5);
- dx=xo=x;
- dy=yo=y;
- xy_ll(dx,dy,&lat,&lon);
- #ifdef COREOFF
- if(ans=='l')
- {
- for(i=0;i<M.NumSymbol;i++)
- {
- if(PlaceFile[i].on==1&&
- pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
- {
- symbol_plot(i,1);
- }
- }
- }
- #endif
- if(ans=='i')
- {
- for(i=0;i<M.NumSymbol;i++)
- {
- if(PlaceFile[i].on==1&&
- pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
- {
- symbol_plot(i,2);
- }
- }
- }
- if(ans=='m')
- {
- cursor(0,x,y,M.White,5);
- tcursor(0,x,y,5,tbuff);
- cursor(0,x,y,M.White,5);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%10.6lf %11.6lf\n",lat,lon);
- }
- paint_box(0,M.Back,MT_Buff,0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- if(val>0)
- {
- sprintf(string,"%3d %s %9.6lf %11.6lf",val,M.Fill_Name[val],lat,lon);
- if(strlen(string)>65)
- {
- printf("string too long -- strlen(string) = %d\n",strlen(string));
- exit(0);
- }
- }
- else
- {
- sprintf(string," %9.6lf %11.6lf",lat,lon);
- if(strlen(string)>65)
- {
- printf("string too long -- strlen(string) = %d\n",strlen(string));
- exit(0);
- }
- }
- plot_font_h(M.White,2,ScreenYs-30/lsize,string,lsize,Font);
- if(ans=='n'&&(VideoType=='X'||VideoType=='S'||VideoType=='Y'))
- {
- uncursor(0,xo,yo,5,tbuff);
- if(val>=0&&strlen(M.Fill_Name[val])>0)
- plot_font_h(color,x-strlen(M.Fill_Name[val])*15/lsize/2,y-13/lsize,
- M.Fill_Name[val],lsize,Font);
- tcursor(0,x,y,5,tbuff);
- cursor(0,x,y,color,5);
- xo=x;yo=y;
- }
- if(ans=='D'&&(BackBright>0.11))
- {
- BackBright-=0.10;
- set_back();
- }
- if(ans=='B'&&(BackBright<2.0))
- {
- BackBright+=0.10;
- set_back();
- }
- if(ans=='P')
- {
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- uncursor(0,xo,yo,5,tbuff);
- i=0;
- while((string[i++]=getch())!=13);
- string[i]='\0';
- sscanf(string,"%d",&clr);
- if(clr>=0&&clr<=M.Max_Fill)
- {
- dx=xo;dy=yo;
- xy_ll(dx,dy,&lat,&lon);
- if(FpLab)
- fprintf(FpLab," 0 0 %9.6lf %11.6lf %3d %3d\n",
- lat,lon,clr,clr);
- if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
- auto_fill_in(0,clr+16,MT_Buff,todo,xo,yo);
- else
- {
- val1=M.Fill_Color[clr][0];
- val2=M.Fill_Color[clr][1];
- if(val1==M.Back)
- val1=M.Black;
- if(val2==M.Back)
- val2=M.Black;
- auto_fill_in_2(0,val1,val2,Mbuff,todo,xo,yo);
- }
- }
- tcursor(0,xo,yo,5,tbuff);
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- cursor(0,xo,yo,color,5);
- }
- if(ans=='p'&&(VideoType=='X'||VideoType=='S'||VideoType=='Y'))
- {
- uncursor(0,xo,yo,5,tbuff);
- clr=getpt(0,xo,yo)-16;
- dx=xo;dy=yo;
- xy_ll(dx,dy,&lat,&lon);
- if(FpLab)
- fprintf(FpLab," 0 0 %9.6lf %11.6lf %3d %3d\n",
- lat,lon,clr,clr);
- tcursor(0,xo,yo,5,tbuff);
- cursor(0,xo,yo,color,5);
- }
- if(ans=='f'||ans=='F')
- {
- tcolor[0]=M.lut[val+16].r;
- tcolor[1]=M.lut[val+16].g;
- tcolor[2]=M.lut[val+16].b;
- M.lut[val+16].r=255;
- M.lut[val+16].g=255;
- M.lut[val+16].b=255;
- WritePalette(M.lut);
- M.lut[val+16].r=tcolor[0];
- M.lut[val+16].g=tcolor[1];
- M.lut[val+16].b=tcolor[2];
- if(getch()==0)
- getch();
- WritePalette(M.lut);
- }
- if(ans=='E'&&val>0) /* edit colors */
- {
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-64/lsize,20*15/lsize,64/lsize);
- do
- {
- paint_box(0,M.Back,MT_Buff,0,ScreenYs-64/lsize,
- 20*15/lsize,64/lsize);
- sprintf(String,"I=%4.2f H=%3.0f S=%4.2f",
- M.Fill_Color_IHS[val][0],M.Fill_Color_IHS[val][1],
- M.Fill_Color_IHS[val][2]);
- plot_font_h(M.White,1,ScreenYs-64/lsize+1,String,lsize,Font);
- sprintf(String," %4.2f %3d %4.2f",fspeed,cspeed,fspeed*2.0);
- plot_font_h(M.White,1,ScreenYs-32/lsize+1,String,lsize,Font);
- ans2=getch();
- if(ans2=='-')
- {
- if(cspeed>1)
- cspeed/=2;
- if(fspeed>0.01)
- fspeed/=2.0;
- }
- if(ans2=='+')
- {
- if(cspeed<64)
- cspeed*=2;
- if(fspeed<0.16)
- fspeed*=2.0;
- }
- if(ans2==0)
- {
- ans3=getch();
- if(ans3==71)
- M.Fill_Color_IHS[val][0]+=fspeed;
- if(ans3==79)
- M.Fill_Color_IHS[val][0]-=fspeed;
- if(M.Fill_Color_IHS[val][0]>1.0)
- M.Fill_Color_IHS[val][0]=1.0;
- if(M.Fill_Color_IHS[val][0]<0.0)
- M.Fill_Color_IHS[val][0]=0.0;
- if(ans3==73)
- M.Fill_Color_IHS[val][2]+=fspeed*2.0;
- if(ans3==81)
- M.Fill_Color_IHS[val][2]-=fspeed*2.0;
- if(M.Fill_Color_IHS[val][2]>1.0)
- M.Fill_Color_IHS[val][2]=1.0;
- if(M.Fill_Color_IHS[val][2]<0.0)
- M.Fill_Color_IHS[val][2]=0.0;
- if(ans3==72)
- M.Fill_Color_IHS[val][1]+=cspeed;
- if(ans3==80)
- M.Fill_Color_IHS[val][1]-=cspeed;
- if(M.Fill_Color_IHS[val][1]>255)
- M.Fill_Color_IHS[val][1]-=256;
- if(M.Fill_Color_IHS[val][1]<0)
- M.Fill_Color_IHS[val][1]+=256;
- set_lut('c',1);
- }
- }while(ans2!=27&&ans2!=13);
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-64/lsize,20*15/lsize,64/lsize);
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- }
- if(ans=='C') /* print data in 'mapper.out' */
- set_lut('c',0);
- if(ans=='A')
- {
- for(i=0;i<ScreenYs;i++)
- {
- for(j=0;j<ScreenXs;j++)
- {
- if((i+j)%2==0)
- MT_Buff[0][j]=(j*16)/ScreenXs;
- else
- MT_Buff[0][j]=(i*16)/ScreenYs;
- }
- plotrow(0,0,ScreenXs-1,i,MT_Buff[0]);
- }
- }
- if(ans=='k'&&M.Fill_In>0)
- {
- ScreenXs=MaxXs;
- M.KeyPlotted=0;
- if(VideoType!='S')
- plot_key(ScreenXs,0,3);
- else
- plot_key(ScreenXs,0,4);
- screen_xs=ScreenXs;
- xy_ll((double)(ScreenXs/2),(double)(ScreenYs/2),&lat,&lon);
- miv.indat[0]=M.Pixsize;
- miv.indat[1]=M.Clat=lat;
- miv.indat[2]=M.Clon=lon;
- miv.indat[3]=M.Clon;
- miv.indat[4]=M.Clat+10;
- miv.indat[5]=M.Clat-10;
- map_pos.xc=0;
- map_pos.yc=0;
- map_pos.xs=ScreenXs;
- map_pos.ys=ScreenYs;
- auto_set_cc(miv.type,miv.indat);
- ScreenXs=MaxXs;
- }
- if(ans=='K'&&M.Fill_In>0)
- {
- ScreenXs=MaxXs;
- M.KeyPlotted=0;
- if(VideoType!='S')
- plot_key(ScreenXs,0,2);
- else
- plot_key(ScreenXs,0,3);
- screen_xs=ScreenXs;
- xy_ll((double)(ScreenXs/2),(double)(ScreenYs/2),&lat,&lon);
- miv.indat[0]=M.Pixsize;
- miv.indat[1]=M.Clat=lat;
- miv.indat[2]=M.Clon=lon;
- miv.indat[3]=M.Clon;
- miv.indat[4]=M.Clat+10;
- miv.indat[5]=M.Clat-10;
- map_pos.xc=0;
- map_pos.yc=0;
- map_pos.xs=ScreenXs;
- map_pos.ys=ScreenYs;
- auto_set_cc(miv.type,miv.indat);
- ScreenXs=MaxXs;
- }
- if(ans=='S'&&M.NumSymbol>0)
- {
- if(search_points(&x,&y,M.Pixsize,string)>0)
- {
- paint_box(0,M.Back,MT_Buff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- uncursor(0,xo,yo,5,tbuff);
- val=getpt(0,x,y)-16;
- color=M.Comp_Color[val+16];
- tcursor(0,x,y,5,tbuff);
- cursor(0,x,y,color,5);
- xo=x;yo=y;
- plot_font_h(M.White,2,ScreenYs-30/lsize,string,lsize,Font);
- }
- }
- if(ans=='x'&&M.NumSymbol>0) /* look at pictures */
- {
- if(search_points(&x,&y,M.Pixsize,string)>0)
- {
- picture_view(string);
- if(unsave_map(LastMap)>0)
- {
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- uncursor(0,xo,yo,5,tbuff);
- val=getpt(0,x,y)-16;
- color=M.Comp_Color[val+16];
- tcursor(0,x,y,5,tbuff);
- cursor(0,x,y,color,5);
- xo=x;yo=y;
- plot_font_h(M.White,2,ScreenYs-30/lsize,string,lsize,Font);
- }
- }
- }
- if(ans=='N')
- {
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- for(m=0;m<M.Num_Fill;m++)
- {
- fpblb=open_to_read_binary(M.Fill_In_Name[m]);
- if(fpblb)
- {
- while(fread((char *)idc,sizeof(int),2,fpblb)==2)
- {
- fread((char *)&lat,sizeof(double),1,fpblb);
- fread((char *)&lon,sizeof(double),1,fpblb);
- ll_xy(&dx,&dy,lat,lon);
- ix=dx;iy=dy;
- if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs)
- {
- ival=idc[1];
- color=M.Comp_Color[ival+16];
- if(ival>0)
- {
- if(strlen(M.Fill_Name[ival])>0)
- plot_font_h(color,
- ix-strlen(M.Fill_Name[ival])*15/lsize/2,
- iy-13/lsize,
- M.Fill_Name[ival],lsize,Font);
- }
- }
- }
- }
- }
- fclose(fpblb);
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- }
- if(ans=='R'&&(VideoType=='X'||VideoType=='S'||VideoType=='Y'))
- {
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- remove_boundaries(M.MapFile[0][0].color);
- save_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- }
- xo=x;yo=y;
- }
- uncursor(0,xo,yo,5,tbuff);
- unsave_box(0,M.Back,Mbuff,
- 0,ScreenYs-32/lsize,42*15/lsize,32/lsize);
- *px=x;*py=y;*sp=speed;
- ScreenXs=screen_xs;
- return;
- }
-
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- int picture_view(string)
-
- char *string;
-
- {
- int i,j,k;
- char filename[STR_LEN],str1[50],str2[50],str3[50],str4[50];
- int ans;
- FILE *fp;
- char instring[STR_LEN],infile[STR_LEN];
-
- if(sscanf(string,"%s%s%s%s",str1,str2,str3,str4)<4)
- return(-1);
- sprintf(str1,"?%s*.lbl",str4);
- SetVideoMode(0);
-
- do
- {
- SetCursor(0,0);
- sprintf(infile,"%s.doc",str4);
- fp=fopen(infile,"rt");
- if(fp)
- {
- while(fgets(instring,80,fp)!=NULL)
- printf("%s",instring);
- }
- fclose(fp);
- ans=D_get_file_name(str1,filename);
- if(ans<0)
- {
- video_on();
- return(1);
- }
- strcpy(Hdr[Img].label,filename);
- for(k=0;k<strlen(filename);k++)
- if(filename[k]=='.')
- filename[k]='\0';
- strcpy(string,filename);
- strcat(string,".lbl");
- if(read_lbl(Hdr[Img].label,Img)>0)
- {
- fcloseall();
- video_on();
- process_image(Img);
- SetVideoMode(0);
- }
- }while(ans>=0);
- video_on();
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int process_image(filenum)
-
- int filenum;
-
- {
- int num=0;
- int ix=ScreenXs/2,iy=ScreenYs/2,speed=16;
- int meni_iv=0;
-
- load_image(filenum);
- do
- {
- num=M_do_menu(Menu_iv,MENU_IV,MENUXC,25,num,D_Grey,L_Grey,White,Font);
- if(num==0)
- {
- load_image(filenum);
- }
- }while(num<MENU_IV-1);
- ZoomSample=1;
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int load_image(filenum)
-
- int filenum;
-
- {
- int i,j,k;
- int sample=0;
- int xs,ys;
- FILE *fp;
- long offset=0;
- char string[100];
-
- Row=Hdr[filenum].row;
- Col=Hdr[filenum].col;
- if(VideoType=='S')
- Speed=8;
-
- if(Hdr[filenum].sample_bits==0)
- Hdr[filenum].sample_bits=8;
-
- if((Row==0||Col==0)&&Hdr[filenum].row_col_header==0)
- return(-1);
- fp=open_to_read_binary(Hdr[filenum].image);
- if(!fp)
- return(-1);
- if(Hdr[filenum].row_col_header==1)
- {
- fread((char *)&Hdr[filenum].row,sizeof(int),1,fp);
- fread((char *)&Hdr[filenum].col,sizeof(int),1,fp);
- Col=Hdr[filenum].col;
- Row=Hdr[filenum].row;
- if(Row<=0||Col<=0)
- return(-1);
- }
- else if(Hdr[filenum].imbedded_header==1)
- {
- offset=Hdr[filenum].col;
- fseek(fp,offset,SEEK_SET);
- }
- else if(Hdr[filenum].header_bytes>0)
- {
- offset=Hdr[filenum].header_bytes;
- fseek(fp,offset,SEEK_SET);
- }
- video_on();
- do
- {
- Sample=sample+=1;
- Row=Hdr[filenum].row/sample;
- Col=Hdr[filenum].col/sample;
- offset=(sample-1);
- offset*=Hdr[filenum].col;
- }while(Col>ScreenXs||Row>ScreenYs);
- Hdr[filenum].sample=sample;
- if(Hdr[filenum].pal_type>0)
- IV_set_lut(Hdr[filenum].pal_type);
- else
- {
- if(IV_set_lut('P',Hdr[filenum].Lut)<0)
- IV_set_lut('G');
- }
- plot_full_image(fp,sample,filenum);
-
- if(sample>1)
- {
- sample=ZoomSample;
- if(limit_area_fixed(&Xc,&Yc,&xs,&ys,&Speed,&sample)!=27)
- {
- ZoomSample=sample;
- plot_sub_image(fp,sample,filenum);
- }
- else
- {
- ZoomSample=Sample;
- }
- }
- fclose(fp);
- }
-
- /********************************************************************
- **
- ** type g -- grey all lut[] files
- ** G -- grey only lut[]
- ** i -- initial header map
- ** r -- reset lut[] to lutc[]
- ** p -- positive (0-127) magenta, negative (128-255) green
- **
- ********************************************************************* */
-
- int IV_set_lut(type,filename)
-
- char type,*filename;
-
- {
- int i,k,hue,brite,j;
- int r,g,b;
- float color[3];
- double dbrite,dval;
- float val,minval,sat,inten;
- float fval,fk;
- FILE *fplut;
- int end=0,scale,sum;
- char string[100];
- long del,mindel,l1,l2,l3,l4;
-
- scale=1;
- if(Num_Color==16)
- scale=17;
- if(type=='P')
- {
- fplut=open_to_read_binary(filename);
- if(fplut)
- {
- i=0;
- do
- {
- i+=1;
- fscanf(fplut,"%s",string);
- }while(strcmpi(string,"end")!=0&&i<50);
- if(strcmpi(string,"end")!=0)
- rewind(fplut);
- for(i=0;i<256;i++)
- {
- fscanf(fplut,"%d%d%d%d",&k,&r,&g,&b);
- Hdr[Img].lut[i].r=r;
- Hdr[Img].lut[i].g=g;
- Hdr[Img].lut[i].b=b;
- }
- fclose(fplut);
- }
- else
- return(-1);
- if(VideoType=='V'||VideoType=='E')
- {
- for(i=0;i<256;i++)
- {
- sum=(int)Hdr[Img].lut[i].r*10;
- sum+=(int)Hdr[Img].lut[i].g*8;
- sum+=(int)Hdr[Img].lut[i].b*2;
- sum/=319;
- Hdr[Img].vga_color[i]=sum;
- }
- for(k=0;k<Num_Color;k++)
- {
- Hdr[Img].lut[k].r=k*scale;
- Hdr[Img].lut[k].g=k*scale;
- Hdr[Img].lut[k].b=k*scale;
- }
- }
- ActiveLut='P';
- }
- if(type=='g')
- {
- for(k=0;k<Num_Color;k++)
- {
- Hdr[Img].lutc[k].r=Hdr[Img].lut[k].r=k*scale;
- Hdr[Img].lutc[k].g=Hdr[Img].lut[k].g=k*scale;
- Hdr[Img].lutc[k].b=Hdr[Img].lut[k].b=k*scale;
- }
- ActiveLut='g';
- }
- if(type=='G')
- {
- for(k=0;k<Num_Color;k++)
- {
- Hdr[Img].lut[k].r=k*scale;
- Hdr[Img].lut[k].g=k*scale;
- Hdr[Img].lut[k].b=k*scale;
- }
- ActiveLut='G';
- }
- if(type=='i')
- {
- for(k=0;k<Num_Color;k++)
- {
- Hdr[Img].lutc[k].r=Hdr[Img].lut[k].r=k*scale;
- Hdr[Img].lutc[k].g=Hdr[Img].lut[k].g=k*scale;
- Hdr[Img].lutc[k].b=Hdr[Img].lut[k].b=k*scale;
- }
- Hdr[Img].lut[ 64].r= 0;Hdr[Img].lut[ 64].g= 0;Hdr[Img].lut[ 64].b=128;
- Hdr[Img].lut[127].r= 0;Hdr[Img].lut[127].g=100;Hdr[Img].lut[127].b= 0;
- Hdr[Img].lut[191].r=255;Hdr[Img].lut[191].g= 0;Hdr[Img].lut[191].b= 0;
- Hdr[Img].lut[192].r=255;Hdr[Img].lut[192].g=128;Hdr[Img].lut[192].b= 0;
- Hdr[Img].lut[193].r=255;Hdr[Img].lut[193].g=255;Hdr[Img].lut[193].b= 0;
- Hdr[Img].lut[194].r= 0;Hdr[Img].lut[194].g=255;Hdr[Img].lut[194].b= 0;
- Hdr[Img].lut[195].r= 0;Hdr[Img].lut[195].g=255;Hdr[Img].lut[195].b=255;
- Hdr[Img].lut[196].r= 20;Hdr[Img].lut[196].g= 55;Hdr[Img].lut[196].b=255;
- Hdr[Img].lut[253].r=100;Hdr[Img].lut[253].g= 1;Hdr[Img].lut[253].b= 1;
- Hdr[Img].lut[254].r=100;Hdr[Img].lut[254].g= 1;Hdr[Img].lut[254].b= 1;
- ActiveLut='i';
- }
- if(type=='r')
- {
- for(k=0;k<Num_Color;k++)
- {
- Hdr[Img].lut[k].r=Hdr[Img].lutc[k].r;
- Hdr[Img].lut[k].g=Hdr[Img].lutc[k].g;
- Hdr[Img].lut[k].b=Hdr[Img].lutc[k].b;
- }
- ActiveLut='r';
- }
- mindel=16777216;
- for(i=0;i<Num_Color;i++)
- {
- l1=Blk.r;
- l2=Hdr[Img].lut[i].r;
- l3=Hdr[Img].lut[i].g;
- l4=Hdr[Img].lut[i].b;
- del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
- if(del<mindel)
- {
- mindel=del;
- Black=i;
- }
- }
- mindel=16777216;
- for(i=0;i<Num_Color;i++)
- {
- l1=D_G.r;
- l2=Hdr[Img].lut[i].r;
- l3=Hdr[Img].lut[i].g;
- l4=Hdr[Img].lut[i].b;
- del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
- if(del<mindel)
- {
- mindel=del;
- D_Grey=i;
- }
- }
- mindel=16777216;
- for(i=0;i<Num_Color;i++)
- {
- l1=M_G.r;
- l2=Hdr[Img].lut[i].r;
- l3=Hdr[Img].lut[i].g;
- l4=Hdr[Img].lut[i].b;
- del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
- if(del<mindel)
- {
- mindel=del;
- M_Grey=i;
- }
- }
- mindel=16777216;
- for(i=0;i<Num_Color;i++)
- {
- l1=L_G.r;
- l2=Hdr[Img].lut[i].r;
- l3=Hdr[Img].lut[i].g;
- l4=Hdr[Img].lut[i].b;
- del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
- if(del<mindel)
- {
- mindel=del;
- L_Grey=i;
- }
- }
- mindel=16777216;
- for(i=0;i<Num_Color;i++)
- {
- l1=Wht.r;
- l2=Hdr[Img].lut[i].r;
- l3=Hdr[Img].lut[i].g;
- l4=Hdr[Img].lut[i].b;
- del=(l1-l2)*(l1-l2)+(l1-l3)*(l1-l3)+(l1-l4)*(l1-l4);
- if(del<mindel)
- {
- mindel=del;
- White=i;
- }
- }
- WritePalette(Hdr[Img].lut);
- return(1);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int plot_sub_image(fp,sample,filenum)
-
- FILE *fp;
- int sample,filenum;
-
- {
- int i,j,k;
- long offset;
-
- rewind(fp);
- paint_box(3,0,Mbuff,0,0,ScreenXs,ScreenYs);
- offset=Hdr[filenum].col;
- offset*=Yc*Sample;
- offset+=Xc*Sample;
- if(Hdr[filenum].header_bytes>0)
- offset+=Hdr[filenum].header_bytes;
- fseek(fp,offset,SEEK_SET);
- Row=ScreenYs;
- Col=ScreenXs;
- if((Yc*Sample+Row*sample)>Hdr[filenum].row)
- Row=(Hdr[filenum].row-Yc*Sample)/sample;
- if((Xc*Sample+Col*sample)>Hdr[filenum].col)
- Col=(Hdr[filenum].col-Xc*Sample)/sample;
- offset=Hdr[filenum].col;
- offset*=(sample-1);
- for(i=0;i<Row;i++)
- {
- if(fread((char *)Mbuff[0],sizeof(char),Hdr[filenum].col,fp)<1)
- {
- return(-1);
- }
- fseek(fp,offset,SEEK_CUR);
- if(sample>1)
- for(j=0;j<Col;j++)
- Mbuff[0][j]=Mbuff[0][j*sample];
- if(VideoType=='V'||VideoType=='E')
- {
- if(ActiveLut=='P')
- {
- for(j=0;j<Col;j++)
- Mbuff[0][j]=Hdr[filenum].vga_color[Mbuff[0][j]];
- }
- else
- {
- for(j=0;j<Col;j++)
- Mbuff[0][j]/=16;
- }
- }
- plotrow(3,0,Col-1,i,Mbuff[0]);
- }
-
- return(1);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int plot_full_image(fp,sample,filenum)
-
- FILE *fp;
- int sample,filenum;
-
- {
- int i,j,k;
- long offset;
- char string[100];
- int row,col;
- FILE *fpsub;
-
- strcpy(string,Hdr[filenum].image);
- for(i=0;i<strlen(string);i++)
- if(string[i]=='.')
- string[i]='\0';
- strcat(string,SubType);
- fpsub=open_to_read_binary(string);
- if(fpsub)
- {
- fread((char *)&row,sizeof(int),1,fpsub);
- fread((char *)&col,sizeof(int),1,fpsub);
- for(i=0;i<row;i++)
- {
- fread((char *)Mbuff[0],sizeof(char),col,fpsub);
- plotrow(0,0,col-1,i,Mbuff[0]);
- }
- fclose(fpsub);
- }
- else
- {
- rewind(fp);
- offset=Hdr[filenum].header_bytes;
- if(offset>0)
- fseek(fp,offset,SEEK_SET);
- offset=(sample-1);
- offset*=Hdr[filenum].col;
- for(i=0;i<Row;i++)
- {
- fread((char *)Mbuff[0],sizeof(char),Hdr[filenum].col,fp);
- if(offset>0)
- fseek(fp,offset,SEEK_CUR);
- if(sample>1)
- for(j=0;j<Col;j++)
- Mbuff[0][j]=Mbuff[0][j*sample];
- if(VideoType=='V'||VideoType=='E')
- {
- if(ActiveLut=='P')
- {
- for(j=0;j<Col;j++)
- Mbuff[0][j]=Hdr[filenum].vga_color[Mbuff[0][j]];
- }
- else
- {
- for(j=0;j<Col;j++)
- Mbuff[0][j]/=16;
- }
- }
- plotrow(3,0,Col-1,i,Mbuff[0]);
- }
- if(sample>1)
- {
- fpsub=open_to_write_binary(string);
- if(fpsub)
- {
- fwrite((char *)&Row,sizeof(int),1,fpsub);
- fwrite((char *)&Col,sizeof(int),1,fpsub);
- for(i=0;i<Row;i++)
- {
- getrow(0,0,Col-1,i,Mbuff[0]);
- fwrite((char *)Mbuff[0],sizeof(char),Col,fpsub);
- }
- fclose(fpsub);
- }
- }
- }
- }
-
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int limit_area_fixed(xc,yc,xs,ys,speed,sample)
-
- int *xc,*yc,*xs,*ys,*speed,*sample;
-
- {
- int i,j,k;
- int xco=*xc,yco=*yc,xso,yso;
- char ans;
-
- xso=*xs=ScreenXs/Sample*(*sample);
- yso=*ys=ScreenYs/Sample*(*sample);
-
- tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Black,White,Center);
- do
- {
- ans=getch();
- unbox(3,*xc,*yc,*xs,*ys,Mbuff);
- if(ans==27)
- {
- return(27);
- }
- else if(ans=='-'&&*speed>1)*speed/=2;
- else if(ans=='+'&&*speed<ScreenYs)*speed*=2;
- else if(ans=='l'&&*sample<Sample)
- *sample+=1;
- else if(ans=='s'&&*sample>1)
- *sample-=1;
- *xs=ScreenXs/Sample*(*sample);
- *ys=ScreenYs/Sample*(*sample);
-
- if(ans==0)
- {
- ans=getch();
- if(ans==71)
- {
- *xc-=*speed;
- *yc-=*speed;
- }
- else if(ans==73)
- {
- *xc+=*speed;
- *yc-=*speed;
- }
- else if(ans==79)
- {
- *xc-=*speed;
- *yc+=*speed;
- }
- else if(ans==81)
- {
- *xc+=*speed;
- *yc+=*speed;
- }
- else if(ans==72)
- *yc-=*speed;
- else if(ans==80)
- *yc+=*speed;
- else if(ans==75)
- *xc-=*speed;
- else if(ans==77)
- *xc+=*speed;
- }
- if(*xs>ScreenXs)*xs=ScreenXs;
- if(*ys>ScreenYs)*ys=ScreenYs;
- if(*xs<2)*xs=2;
- if(*ys<2)*ys=2;
- if((*xc+*xs)>=ScreenXs)*xc=ScreenXs-*xs;
- if((*yc+*ys)>=ScreenYs)*yc=ScreenYs-*ys;
- if(*xc<0)*xc=0;
- if(*yc<0)*yc=0;
- tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Black,White,Center);
- }while(ans!=83&&ans!=27&&ans!=13);
- unbox(3,*xc,*yc,*xs,*ys,Mbuff);
- return(ans);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int read_lbl(label,filenum)
-
- char *label;
- int filenum;
-
- {
- int i,j,k;
- char string1[100],string2[100],string3[100];
- FILE *fp;
- int status=1,numread;
-
- fp=open_to_read_binary(label);
- if(!fp)
- return(-1);
- Hdr[filenum].sample_bits=Hdr[filenum].record_bytes=0;
- Hdr[filenum].file_records=0;
- Hdr[filenum].pal_type=0;
- Hdr[filenum].row_col_header=0;
- Hdr[filenum].Lut[0]='\0';
- while(fscanf(fp,"%s",string1)==1)
- {
- if(strcmpi(string1,"end")==0)
- {
- fclose(fp);
- return(status);
- }
- if(strcmpi(string1,"image_lines")==0&&Hdr[filenum].file_records==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- sscanf(string3,"%d",&Hdr[filenum].row);
- printf("Row = %d\n",Hdr[filenum].row);
- }
- if(strcmpi(string1,"sample_bits")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- sscanf(string3,"%d",&Hdr[filenum].sample_bits);
- printf("Sample_Bits = %d\n",Hdr[filenum].sample_bits);
- }
- if(strcmpi(string1,"file_records")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- sscanf(string3,"%d",&Hdr[filenum].row);
- printf("Row = %d\n",Hdr[filenum].row);
- Hdr[filenum].file_records=Hdr[filenum].row;
- }
- if(strcmpi(string1,"line_samples")==0&&Hdr[filenum].record_bytes==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- sscanf(string3,"%d",&Hdr[filenum].col);
- printf("Col = %d\n",Hdr[filenum].col);
- }
- if(strcmpi(string1,"record_bytes")==0||
- strcmpi(string1,"image_record_bytes")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- sscanf(string3,"%d",&Hdr[filenum].col);
- printf("Col = %d\n",Hdr[filenum].col);
- Hdr[filenum].record_bytes=Hdr[filenum].col;
- }
- if(strcmpi(string1,"header_bytes")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- sscanf(string3,"%d",&Hdr[filenum].header_bytes);
- printf("Header_Bytes = %d\n",Hdr[filenum].header_bytes);
- }
- if(strcmpi(string1,"image_pointer")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- k=0;
- for(i=0;i<strlen(string3);i++)
- if(string3[i]!=39) /* single quote */
- Hdr[filenum].image[k++]=string3[i];
- Hdr[filenum].image[k]='\0';
- printf("Image = %s\n",Hdr[filenum].image);
- }
- if(strcmpi(string1,"pal_type")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- k=0;
- for(i=0;i<strlen(string3);i++)
- if(string3[i]!=39) /* single quote */
- string1[k++]=string3[i];
- string1[k]='\0';
- Hdr[filenum].pal_type=string1[0];
- printf("Pal_Type = %c\n",Hdr[filenum].pal_type);
- }
- if(strcmpi(string1,"pal_pointer")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- k=0;
- for(i=0;i<strlen(string3);i++)
- if(string3[i]!=39) /* single quote */
- Hdr[filenum].Lut[k++]=string3[i];
- Hdr[filenum].Lut[k]='\0';
- printf("Lut = %s\n",Hdr[filenum].Lut);
- }
- if(strcmpi(string1,"row_col_header")==0)
- {
- numread=fscanf(fp,"%s%s",string2,string3);
- if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0||
- numread<2)
- {
- fclose(fp);
- return(status);
- }
- Hdr[filenum].row_col_header=1;
- Hdr[filenum].header_bytes=4;
- }
- }
- fclose(fp);
- return(status);
- }
-
-
-
- /********************************************************************
- **
- ** returns:
- **
- ** -3 -- too many files of type given
- ** -2 -- no such files
- ** -1 -- no file chosen
- ** >=0 -- number of file chosen = n of String[n]
- **
- **
- ********************************************************************* */
-
- int D_get_file_name(file_id,file_name)
-
- char *file_id,*file_name;
-
- {
- int i,j,k;
- int num_files;
- int val=-2;
- char string[NAME_SIZE],file[F_SIZE],type[T_SIZE],directory[NAME_SIZE];
- int t=0,d=0,ls=-1;
- char s2[100];
-
- Monitor=check_equip(&Eq);
-
- for(i=0;i<strlen(file_id);i++)
- if(file_id[i]=='\\')
- ls=i;
- if(ls>0)
- {
- d=1;
- strcpy(directory,file_id);
- directory[ls+1]='\0';
- }
- else
- directory[0]='\0';
-
- num_files=D_load_File(file_id);
- if(num_files<0)
- return(num_files);
- else
- {
- ClearBox(40,79,0,0,112);
- sprintf(string," core id Top (ft) Bottom (ft)");
- WriteStringAtxy(40,0,39,(char)112,string);
- val=scroll_list(40,1,40,21,GF_String,num_files,file_name);
- if(val>=0)
- {
- strcpy(s2,file_name);
- sprintf(file_name,"%c%c%c%c%c%c%c%c.lbl",
- s2[0],s2[2],s2[3],s2[4],s2[5],s2[7],s2[8],s2[9]);
- }
- }
- return(val);
- }
-
- /********************************************************************
- **
- ** looks for a file named in a global char *DepthFile
- **
- ** format is:
- **
- ** filename top_depth_in_feet bottom_depth_in_feet
- **
- ** e.g.:
- **
- ** D356001 5472 5497
- ** D356002 5497 5524
- ** D356003 5524 5551
- ** D356004 5551 5573
- **
- ********************************************************************* */
-
- int D_load_File(instring)
-
- char *instring;
-
- {
- int i,i1;
- int num_files;
- int mo,da,yr,hr,min;
- char string[100],type[100],path[100];
- FILE *fpin;
- char name[100];
- float d1,d2;
-
- num_files=load_names(instring);
- if(num_files>=MAX_NUM)
- return(-3);
- if(num_files==0)
- return(-2);
- sort_name(num_files);
-
- fpin=open_to_read_binary(DepthFile);
- if(!fpin)
- {
- printf("Could not open '%s'\n",DepthFile);
- exit(0);
- }
- for(i=0;i<num_files;i++)
- {
- i1=GF_Order[i];
- file_name(GF_File[i1].name,string,type);
- date_convert(GF_File[i1].date,&mo,&da,&yr);
- time_convert(GF_File[i1].time,&hr,&min);
- sprintf(GF_String[i],"%s %s%9ld %2d/%02d/%2d %02d%02d "
- ,string,type,GF_File[i1].size,mo,da,yr,hr,min);
- }
- while(fscanf(fpin,"%s%f%f",name,&d1,&d2)==3)
- {
- for(i=0;i<num_files;i++)
- {
- i1=GF_Order[i];
- split(GF_File[i1].name,path,string,type);
- {
- if(strcmpi(string,name)==0)
- {
- if(string[0]=='T'||string[0]=='t')
- sprintf(GF_String[i],
- "%c %c%c%c%c %c%c%c %8.2f ",
- string[0],string[1],string[2],string[3],
- string[4],string[5],string[6],string[7],d1);
- else
- sprintf(GF_String[i],
- "%c %c%c%c%c %c%c%c %5.0f %5.0f ",
- string[0],string[1],string[2],string[3],
- string[4],string[5],string[6],string[7],d1,d2);
- D1[i1]=d1;
- D2[i1]=d2;
- }
- }
- }
- }
- return(num_files);
- }
-
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- int add_graticule()
-
- {
- float pixsize=M.Pixsize;
- double sp;
-
- miv.type=M.Type;
- miv.indat[0]=pixsize;
- miv.indat[1]=M.Clat;
- miv.indat[2]=M.Clon;
- miv.indat[3]=M.Clon;
- miv.indat[4]=M.Clat+10;
- miv.indat[5]=M.Clat-10;
- map_pos.xc=0;
- map_pos.yc=0;
- map_pos.xs=ScreenXs;
- map_pos.ys=ScreenYs;
- auto_set_cc(miv.type,miv.indat);
- screen_mm();
-
- if(pixsize>5.0)
- {
- sp=10;
- plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize>2.5&&pixsize<=5.0)
- {
- sp=5;
- plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=2.5&&pixsize>0.5)
- {
- sp=1;
- plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.5&&pixsize>0.25)
- {
- sp=0.5;
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.25&&pixsize>0.05)
- {
- sp=0.1;
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.05&&pixsize>0.025)
- {
- sp=0.05;
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.025&&pixsize>0.005)
- {
- sp=0.01;
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.005&&pixsize>0.0025)
- {
- sp=0.005;
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.0025)
- {
- sp=0.001;
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- }
-
-
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- FILE *open_to_write_text(name)
-
- char *name;
-
- {
- int i,j,k;
- FILE *fp;
- char string[STR_LEN];
-
- for(j=0;j<NumPath;j++)
- {
- sprintf(string,"%s%s",Path[j],name);
- fp=fopen(string,"wt");
- if(fp)
- {
- strcpy(LastFile,name);
- return(fp);
- }
- }
- clearerr(fp);
- fp=NULL;
- return(fp);
- }
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- FILE *open_to_write_binary(name)
-
- char *name;
-
- {
- int i,j,k;
- FILE *fp;
- char string[STR_LEN];
-
- for(j=0;j<NumPath;j++)
- {
- sprintf(string,"%s%s",Path[j],name);
- fp=fopen(string,"wb");
- if(fp)
- {
- strcpy(LastFile,name);
- return(fp);
- }
- }
- clearerr(fp);
- fp=NULL;
- return(fp);
- }
-
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- FILE *open_to_read_binary(name)
-
- char *name;
-
- {
- int i,j,k;
- FILE *fp;
- char string[STR_LEN];
- int len;
-
- string[0]='\0';
- for(j=0;j<NumPath;j++)
- {
- len=strlen(Path[j])+strlen(name);
- if(len>0&&len<STR_LEN);
- {
- sprintf(string,"%s%s",Path[j],name);
- fp=fopen(string,"rb");
- if(fp)
- {
- strcpy(LastFile,name);
- return(fp);
- }
- }
- }
- clearerr(fp);
- fp=NULL;
- return(fp);
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int add_disk_path(string)
-
- char *string;
-
- {
- int i,j,k;
- char dsk,pth[STR_LEN],nam[10],typ[10],str[STR_LEN];
- int match,add=0;
-
- dsk=fsplit(string,pth,nam,typ);
- if(dsk>0)
- sprintf(str,"%c:%s",dsk,pth);
- else
- sprintf(str,"%s",pth);
- if((dsk>0||strlen(pth)>0)&&NumPath<NUM_DP)
- {
- match=0;
- for(i=0;i<NumPath;i++)
- {
- if(strcmpi(Path[i],str)==0)
- match=1;
- }
- if(match==0)
- {
- strcpy(Path[NumPath],str);
- NumPath+=1;
- add+=1;
- }
- }
- return(add);
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- char fsplit(instring,path,name,type)
-
- char *instring,*path,*name,*type;
-
- {
- int i,j,k;
- int dot=-1,last_slash=-1,len=strlen(instring),first_slash=-1;
- int num=0,colon=-1;
- int disk=0;
- char string[STR_LEN];
-
- strcpy(string,instring);
- path[0]='\0';
- name[0]='\0';
- type[0]='\0';
-
- for(i=0;i<len;i++)
- {
- if(string[i]==':')
- colon=i;
- else if(string[i]=='\\')
- {
- last_slash=i;
- if(first_slash<0)
- first_slash=i;
- }
- else if(string[i]=='.')
- dot=i;
- }
- if(dot<0&&first_slash>=0&&last_slash<len-1) /* d:test */
- {
- string[len]='\\';
- last_slash=len;
- len+=1;
- string[len]='\0';
- }
- if(dot<0&&first_slash<0&&len>colon-1)
- {
- string[len]='.';
- dot=len;
- len+=1;
- string[len]='\0';
- }
- if(colon>0)
- disk=string[0];
- if(first_slash>=0)
- {
- for(i=first_slash;i<=last_slash;i++)
- path[i-first_slash]=string[i];
- path[last_slash-first_slash+1]='\0';
- }
- if(last_slash>0&&last_slash<len-1&&dot>0)
- {
- for(i=last_slash+1;i<dot;i++)
- name[i-last_slash-1]=string[i];
- name[dot-last_slash-1]='\0';
- }
- if(colon>0&&last_slash<0&&dot>0) /* d:test.img */
- {
- for(i=colon+1;i<dot;i++)
- name[i-colon-1]=string[i];
- name[dot-colon]='\0';
- }
- if(colon<0&&last_slash<0&&dot>0) /* test.img */
- {
- for(i=0;i<dot;i++)
- name[i]=string[i];
- name[dot]='\0';
- }
- if(dot>0&&dot<len-1)
- {
- for(i=dot+1;i<len;i++)
- type[i-dot-1]=string[i];
- type[len-dot-1]='\0';
- if(strlen(type)>3)
- type[3]='\0';
- }
- return(disk);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int annotate(ix,iy,size,color)
-
- int *ix,*iy,*size,*color;
-
- {
- int i,j,k;
- char string[STR_LEN],ans,ans2;
- int xc=*ix,yc=*iy,xs=ScreenXs-(*ix),ys=28/(*size),speed=16;
- int cxc=0,cyc=ScreenYs-28/(*size),cxs=ScreenXs,cys=28/(*size);
- int background=0;
-
- if(*color==0)
- background=M.Back;
- save_box(0,background,Mbuff,cxc,cyc,cxs,cys);
- i=0;
- string[0]='\0';
- do
- {
- ans=getch();
- if(ans==8&&i>0)
- {
- i-=1;
- string[i]='\0';
- unsave_box(0,background,Mbuff,cxc,cyc,cxs,cys);
- save_box(0,background,Mbuff,cxc,cyc,cxs,cys);
- plot_font_h(*color,cxc,cyc,string,*size,Font);
- }
- if(ans>=0x20)
- {
- string[i]=ans;
- string[i+1]='\0';
- plot_font_h(*color,cxc,cyc,string,*size,Font);
- i+=1;
- }
- if(ans==0)
- {
- ans2=getch();
- if(ans2>=71&&ans2<=73)
- *color+=1;
- if(ans2>=79&&ans2<=81)
- *color-=1;
- if(*color>15)
- *color=0;
- if(*color<0)
- *color=15;
- if(*color==0)
- background=M.Back;
- else
- background=0;
- unsave_box(0,background,Mbuff,cxc,cyc,cxs,cys);
- if(ans2==75&&*size<4)
- *size+=1;
- if(ans2==77&&*size>1)
- *size-=1;
- cyc=ScreenYs-28/(*size);
- ys=cys=28/(*size);
- save_box(0,background,Mbuff,cxc,cyc,cxs,cys);
- plot_font_h(*color,cxc,cyc,string,*size,Font);
- }
- }while(ans!=27&&ans!=13);
- unsave_box(0,background,Mbuff,cxc,cyc,cxs,cys);
- if(ans==27)
- return(ans);
- xs=strlen(string)*15/(*size);
- if(limit_area(&xc,&yc,&xs,&ys,&speed,ScreenXs,0,Mbuff)!=27&&
- strlen(string)>0)
- plot_font_h(*color,xc,yc,string,*size,Font);
- *ix=xc;
- *iy=yc;
- return(ans);
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int draw_line(ix,iy,color)
-
- int *ix,*iy,*color;
-
- {
- int i,j,k;
- char string[STR_LEN],ans,ans2;
- int x1=*ix,x2,y1=*iy,y2,speed=16,xo=*ix,yo=*iy;
- int val;
-
- val=getpt(0,x1,y1);
- tcursor(3,x1,y1,7,Mbuff);
- cursor(0,x1,y1,M.Comp_Color[val],7);
- do
- {
- ans=getch();
- if(ans==0)
- {
- ans2=getch();
- if(ans2==71)
- {
- x1-=speed;
- y1-=speed;
- }
- if(ans2==73)
- {
- x1+=speed;
- y1-=speed;
- }
- if(ans2==79)
- {
- x1-=speed;
- y1+=speed;
- }
- if(ans2==81)
- {
- x1+=speed;
- y1+=speed;
- }
- if(ans2==72)
- y1-=speed;
- if(ans2==80)
- y1+=speed;
- if(ans2==75)
- x1-=speed;
- if(ans2==77)
- x1+=speed;
- if(x1<0)
- x1=0;
- if(x1>=ScreenXs)
- x1=ScreenXs-1;
- if(y1<0)
- y1=0;
- if(y1>=ScreenYs)
- y1=ScreenYs-1;
- }
- if(ans=='-'&&speed>2)
- speed/=2;
- if(ans=='+'&&speed<128)
- speed*=2;
- uncursor(3,xo,yo,7,Mbuff);
- val=getpt(0,x1,y1);
- tcursor(3,x1,y1,7,Mbuff);
- cursor(0,x1,y1,M.Comp_Color[val],7);
- xo=x1;
- yo=y1;
- }while(ans!=27&&ans!=13);
- uncursor(3,xo,yo,7,Mbuff);
- if(ans==27)
- return(ans);
- xo=x2=x1;yo=y2=y1;
- tplotln_inv_dot(0,x1,y1,x2,y2,Mbuff,ScreenXs);
- tcursor(3,x2,y2,7,Buffer);
- cursor(0,x2,y2,*color,7);
- do
- {
- ans=getch();
- if(ans==0)
- {
- ans2=getch();
- if(ans2==71)
- {
- x2-=speed;
- y2-=speed;
- }
- if(ans2==73)
- {
- x2+=speed;
- y2-=speed;
- }
- if(ans2==79)
- {
- x2-=speed;
- y2+=speed;
- }
- if(ans2==81)
- {
- x2+=speed;
- y2+=speed;
- }
- if(ans2==72)
- y2-=speed;
- if(ans2==80)
- y2+=speed;
- if(ans2==75)
- x2-=speed;
- if(ans2==77)
- x2+=speed;
- if(x2<0)
- x2=0;
- if(x2>=ScreenXs)
- x2=ScreenXs-1;
- if(y2<0)
- y2=0;
- if(y2>=ScreenYs)
- y2=ScreenYs-1;
- }
- if(ans=='c')
- *color-=1;
- if(ans=='C')
- *color+=1;
- if(*color>15)
- *color=0;
- if(*color<0)
- *color=15;
- if(ans=='-'&&speed>2)
- speed/=2;
- if(ans=='+'&&speed<128)
- speed*=2;
- uncursor(0,xo,yo,7,Buffer);
- unplotln(0,x1,y1,xo,yo,Mbuff);
- xo=x2;
- yo=y2;
- tplotln_inv_dot(0,x1,y1,x2,y2,Mbuff,ScreenXs);
- plotln(0,x1,y1,x2,y2,*color);
- tcursor(0,x2,y2,7,Buffer);
- cursor(0,x2,y2,*color,7);
- }while(ans!=27&&ans!=13);
- uncursor(3,xo,yo,7,Buffer);
- unplotln(0,x1,y1,xo,yo,Mbuff);
- if(ans==27)
- return(ans);
- plotln(0,x1,y1,x2,y2,*color);
- *ix=x2;
- *iy=y2;
- return(ans);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int vector_plot(pixsize)
-
- float pixsize;
-
- {
- int i,j,k;
- int v_num=0,val;
-
- for(i=0;i<M.Num_Type;i++)
- Menu_V[i]=M.Group_Name[i];
- Menu_V[M.Num_Type]=Exit;
- v_num=M_do_menu(Menu_V,M.Num_Type+1,MENUXC,25,v_num,
- M.Mback,M.Text,M.High,Font);
- i=v_num;
- if(i>=0&&i<M.Num_Type)
- {
- for(j=0;j<M.Ns[i];j++)
- {
- if(M.MapFile[i][j].max_pix*PixScale>pixsize
- &&M.MapFile[i][j].min_pix*PixScale<=pixsize)
- {
- if(kbhit()>0)
- {
- val=getch();
- if(val==27)
- return(-2);
- }
- convert_bin(M.MapFile[i][j].color,
- M.MapFile[i][j].filename);
- }
- }
- }
- return(0);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int point_plot(pixsize,start)
-
- float pixsize;
- int start;
-
- {
- int i,j,k;
- int p_num=start,p_numo=start,val;
-
- for(i=0;i<M.NumSymbol;i++)
- Menu_P[i]=PlaceFile[i].name;
- Menu_P[M.NumSymbol]="Plot All";
- Menu_P[M.NumSymbol+1]="All OFF";
- Menu_P[M.NumSymbol+2]="exit";
- do
- {
- p_num=M_do_menu(Menu_P,M.NumSymbol+3,MENUXC,25,p_num,
- M.Mback,M.Text,M.High,Font);
- i=p_num;
- if(i>=0&&i<M.NumSymbol)
- {
- p_numo=p_num;
- PlaceFile[i].on=1;
- if(PlaceFile[i].on==1&&
- pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
- symbol_plot(i,0);
- }
- if(p_num==M.NumSymbol)
- {
- for(i=0;i<M.NumSymbol;i++)
- {
- p_numo=0;
- PlaceFile[i].on=1;
- if(PlaceFile[i].on==1&&
- pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
- symbol_plot(i,0);
- }
- }
- if(p_num==M.NumSymbol+1)
- {
- for(i=0;i<M.NumSymbol;i++)
- {
- p_numo=0;
- PlaceFile[i].on=0;
- }
- }
- }while(p_num<M.NumSymbol);
- return(p_numo);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int search_list(list,string)
-
- char *list,*string;
-
- {
- int i,j,k;
- int p=-1;
- int val,kbval;
-
- for(j=0;j<NumPath;j++)
- {
- if(kbhit()>0)
- {
- kbval=getch();
- if(kbval==27)
- return(-2);
- }
- sprintf(String,"%s%s",Path[j],list);
- if(load_names(String)>0)
- val=get_file_name(String,string);
- else
- val=-1;
- if(val>=0)
- return(val);
- }
- return(val);
- }
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int save_map(name)
-
- char *name;
-
- {
- int i,j,k;
- FILE *fp;
- double lat,lon;
-
- ScreenXs=MaxXs;
- ScreenYs=MaxYs;
- xy_ll((double)(ScreenXs/2),(double)(ScreenYs/2),&lat,&lon);
- miv.indat[0]=M.Pixsize;
- miv.indat[1]=M.Clat=lat;
- miv.indat[2]=M.Clon=lon;
- miv.indat[3]=M.Clon;
- miv.indat[4]=M.Clat+10;
- miv.indat[5]=M.Clat-10;
- map_pos.xc=0;
- map_pos.yc=0;
- map_pos.xs=ScreenXs;
- map_pos.ys=ScreenYs;
- auto_set_cc(miv.type,miv.indat);
- fp=open_to_write_binary(name);
- if(!fp)
- return(-1);
- strcpy(LastMap,LastFile);
- /* setbuf(fp,Inbuff);*/
- M.screen_xs=ScreenXs;
- M.screen_ys=ScreenYs;
- fwrite((char *)&M,sizeof(struct map),1,fp);
- if(M.NumSymbol>0)
- fwrite((char *)PlaceFile,sizeof(struct symbol_name),M.NumSymbol,fp);
- for(i=0;i<MaxYs;i++)
- {
- getrow(0,0,MaxXs-1,i,Buffer);
- fwrite((char *)Buffer,sizeof(char),MaxXs,fp);
- }
- fclose(fp);
- return(1);
- }
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int unsave_map(name)
-
- char *name;
-
- {
- int i,j,k;
- FILE *fp;
-
- ScreenXs=MaxXs;
- ScreenYs=MaxYs;
- fp=open_to_read_binary(name);
- if(fp==NULL)
- return(-1);
- strcpy(LastMap,LastFile);
- /* setbuf(fp,Inbuff);*/
- fread((char *)&M,sizeof(struct map),1,fp);
- if(M.NumSymbol>0)
- fread((char *)PlaceFile,sizeof(struct symbol_name),M.NumSymbol,fp);
- ScreenXs=M.screen_xs;
- ScreenYs=M.screen_ys;
- WritePalette(M.lut);
- for(i=0;i<MaxYs;i++)
- {
- fread((char *)Buffer,sizeof(char),MaxXs,fp);
- plotrow(0,0,MaxXs-1,i,Buffer);
- }
- fclose(fp);
- miv.indat[0]=M.Pixsize;
- miv.indat[1]=M.Clat;
- miv.indat[2]=M.Clon;
- miv.indat[3]=M.Clon;
- miv.indat[4]=M.Clat+10;
- miv.indat[5]=M.Clat-10;
- miv.type=M.Type;
- map_pos.xc=0;
- map_pos.yc=0;
- map_pos.xs=ScreenXs;
- map_pos.ys=ScreenYs;
- auto_set_cc(miv.type,miv.indat);
- screen_mm();
- if(M.Num_Type>NUM_TYPE)
- {
- SetVideoMode(0);
- printf("Too many vector groups.\n");
- exit(0);
- }
- for(i=0;i<M.Num_Type;i++)
- {
- strcpy(T_Menu_L[i][0],M.Group_Name[i]);
- strcat(T_Menu_L[i][0]," OFF");
- strcpy(T_Menu_L[i][1],M.Group_Name[i]);
- strcat(T_Menu_L[i][1]," ON");
- }
- i=M.Num_Type;
- strcpy(T_Menu_L[i+0][0],"all ON");
- strcpy(T_Menu_L[i+0][1],"all ON");
- strcpy(T_Menu_L[i+1][0],"all OFF");
- strcpy(T_Menu_L[i+1][1],"all OFF");
- strcpy(T_Menu_L[i+2][0],"exit");
- strcpy(T_Menu_L[i+2][1],"exit");
- return(1);
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int video_on()
-
- {
- int i,row;
-
- i=GetVideoBoardID();
- #ifdef NUMBER9
- VideoType='X';
- B_Id.row=1024;
- B_Id.col=1024;
- ScreenXs=1024;
- ScreenYs=1024;
- strcpy(Suffix,".nmp");
- FontSize=1;
- #else
- if(VideoType=='X')
- {
- row=SetVideoMode(480,&B_Id);
- if(B_Id.row<400)
- VideoType='V';
- else
- {
- ScreenXs=640;
- ScreenYs=row;
- }
- if(B_Id.row==480)
- strcpy(Suffix,".xmp");
- else
- strcpy(Suffix,".ymp");
- }
- if(VideoType=='Y')
- {
- row=SetVideoMode(400,&B_Id);
- if(B_Id.row<400)
- VideoType='V';
- else
- {
- ScreenXs=640;
- ScreenYs=row;
- }
- strcpy(Suffix,".ymp");
- }
- if(VideoType=='V')
- {
- row=SetVideoMode(0x12,&B_Id);
- if(B_Id.row!=480)
- VideoType='E';
- else
- {
- ScreenXs=640;
- ScreenYs=480;
- Num_Color=M.Num_Color=16;
- strcpy(Suffix,".vmp");
- }
- }
- if(VideoType=='S')
- {
- row=SetVideoMode(0x13,&B_Id);
- if(B_Id.row!=200)
- {
- SetVideoMode(0,&B_Id);
- printf("Could not boot color board.\n");
- exit(0);
- }
- ScreenXs=320;
- ScreenYs=200;
- Num_Color=M.Num_Color=256;
- strcpy(Suffix,".smp");
- FontSize=3;
- }
- if(VideoType=='E')
- {
- row=SetVideoMode(0x10,&B_Id);
- if(B_Id.row!=350)
- {
- SetVideoMode(0,&B_Id);
- printf("Could not boot color board.\n");
- exit(0);
- }
- ScreenXs=640;
- ScreenYs=350;
- Num_Color=M.Num_Color=16;
- strcpy(Suffix,".emp");
- }
- if(B_Id.row<0)
- {
- SetVideoMode(0,&B_Id);
- printf("Could not boot board -- row = %d\n\n",row);
- exit(0);
- }
- #endif
- MaxXs=ScreenXs=B_Id.col;
- MaxYs=ScreenYs=B_Id.row;
- PixScale=480.0;
- PixScale/=(float)ScreenYs;
- strcpy(SubType,Suffix);
- SubType[3]='g';
- }
-
-
-
- /********************************************************************
- **
- ** WARNING!!!! YOU MUST CALL decode_font() or set_files() before using
- **
- ** options:
- **
- ** -1 -- remove menu but get no answer
- ** 0 -- return answer and set menu colors to greys
- ** 1 -- return answer but leave colors alone
- **
- ********************************************************************* */
-
- int M_do_menu(menu,num,xc,yc,start,back,words,boxs,font)
-
- char *menu[];
- int num,xc,yc,start,back,words,boxs;
- int font[128][25];
-
- {
- int i,j,k;
- char ans,ans2;
- int len=0,l,size=FontSize,val,valo;
- int black=0,dgrey=back,lgrey=words,white=boxs;
- int wide;
- long lxs,lys,buffersize=(long)B_LINES*(long)MAX_X;
-
- for(k=0;k<num;k++)
- if((l=strlen(menu[k]))>len)len=l;
- if(len==0)return(-1);
- do
- {
- wide=(len+1)*15/size+1;
- if((ScreenXs-1-wide)<xc)xc=ScreenXs-1-wide;
- lxs=(len+1)*15/size+1;
- lys=30/size*num+1;
- if(lxs*lys>buffersize)
- size+=1;
- if(size>4)
- {
- SetVideoMode(0);
- printf("Could not fit menu into buffer for 'save_box()'\n");
- exit(0);
- }
- }while(lxs*lys>buffersize);
- if((xc+(len+1)*15/size+1)<ScreenXs)
- {
- save_box(0,dgrey,Mbuff,
- xc,yc,(len+1)*15/size+1,30/size*num+1);
- for(k=0;k<num;k++)
- {
- box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
- plot_font_h(lgrey,
- xc+15/size,yc+k*30/size+5/size,menu[k],size,font);
- }
- box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
-
- val=valo=start;
- box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
- do
- {
- if((ans=getch())==0)
- {
- ans2=getch();
- if(ans2==50)
- {
- unsave_box(0,dgrey,Mbuff,
- xc,yc,(len+1)*15/size+1,30/size*num+1);
- getch();
- paint_box(0,dgrey,MT_Buff,
- xc,yc,(len+1)*15/size+1,30/size*num+1);
- for(k=0;k<num;k++)
- {
- plot_font_h(lgrey,
- xc+15/size,
- yc+k*30/size+5/size,menu[k],size,font);
- }
- }
- if(ans2=='H')
- {
- if(val>0)val-=1;
- else val=num-1;
- }
- if(ans2=='P')
- {
- if(val<num-1)val+=1;
- else val=0;
- }
- }
-
- for(i=0;i<num;i++)
- if(ans==menu[i][0])
- {
- val=i;
- ans=13;
- }
-
- box(0,xc,yc+valo*(30/size),dgrey,(len+1)*15/size,30/size);
- valo=val;
- box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
- box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
- if(ans==27)
- {
- val=num-1;
- ans=13;
- }
- }while(ans!=13);
- }
- box(0,xc,yc,dgrey,(len+1)*15/size,30/size*num);
- box(0,xc,yc+val*(30/size),lgrey,(len+1)*15/size,30/size);
- unsave_box(0,dgrey,Mbuff,
- xc,yc,(len+1)*15/size+1,30/size*num+1);
- return(val);
- }
-
-
-
- /********************************************************************
- **
- ** WARNING!!!! YOU MUST CALL decode_font() or set_files() before using
- **
- ** options:
- **
- ** -1 -- remove menu but get no answer
- ** 0 -- return answer and set menu colors to greys
- ** 1 -- return answer but leave colors alone
- **
- ********************************************************************* */
-
- int T_do_menu(menu,num,xc,yc,start,back,words,boxs,font,off_on)
-
- char menu[][2][50];
- int num,xc,yc,start,back,words,boxs;
- int font[128][25],*off_on;
-
- {
- int i,j,k;
- char ans,ans2;
- int len=0,l,size=FontSize,val,valo;
- int black=0,dgrey=back,lgrey=words,white=boxs;
- int wide;
- long lxs,lys,buffersize=(long)B_LINES*(long)MAX_X;
-
- for(k=0;k<num;k++)
- if((l=strlen(menu[k][0]))>len)len=l;
- if(len==0)return(-1);
- do
- {
- wide=(len+1)*15/size+1;
- if((ScreenXs-1-wide)<xc)xc=ScreenXs-1-wide;
- lxs=(len+1)*15/size+1;
- lys=30/size*num+1;
- if(lxs*lys>buffersize)
- size+=1;
- if(size>4)
- {
- SetVideoMode(0);
- printf("Could not fit menu into buffer for 'save_box()'\n");
- exit(0);
- }
- }while(lxs*lys>buffersize);
- if((ScreenXs-1-wide)<xc)xc=ScreenXs-1-wide;
- if((xc+(len+1)*15/size+1)<ScreenXs)
- {
- paint_box(0,dgrey,Mbuff,xc,yc,(len+1)*15/size+1,30/size*num+1);
- for(k=0;k<num-3;k++)
- {
- box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
- plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k][off_on[k]],
- size,font);
- }
- for(k=num-3;k<num;k++)
- {
- box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
- plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k][0],
- size,font);
- }
- box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
-
- val=valo=start;
- box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
- do
- {
- ans=getch();
- if(ans==13)
- {
- if(val<num-3)
- {
- if(off_on[val]==0)
- off_on[val]=1;
- else
- off_on[val]=0;
- }
- if(val==num-3)
- for(k=0;k<num-3;k++)
- off_on[k]=1;
- if(val==num-2)
- for(k=0;k<num-3;k++)
- off_on[k]=0;
- paint_box(0,dgrey,Mbuff,xc,yc,
- (len+1)*15/size+1,30/size*num+1);
- for(k=0;k<num-3;k++)
- {
- box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
- plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,
- menu[k][off_on[k]],size,font);
- }
- for(k=num-3;k<num;k++)
- {
- box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
- plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,
- menu[k][0],size,font);
- }
- box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
- }
- if(ans==13&&val==num-1)
- ans=27;
- if(ans==0)
- {
- ans2=getch();
- if(ans2=='H')
- {
- if(val>0)val-=1;
- else val=num-1;
- }
- if(ans2=='P')
- {
- if(val<num-1)val+=1;
- else val=0;
- }
- }
- for(i=0;i<num;i++)
- if(ans==menu[i][0][0])
- {
- val=i;
- ans=27;
- }
- box(0,xc,yc+valo*(30/size),dgrey,(len+1)*15/size,30/size);
- valo=val;
- box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
- box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
- }while(ans!=27);
- }
- box(0,xc,yc,dgrey,(len+1)*15/size,30/size*num);
- box(0,xc,yc+val*(30/size),lgrey,(len+1)*15/size,30/size);
-
- return(val);
- }
-
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int read_control(filename)
-
- char *filename;
-
- {
- int i,j,k,n=1,m,p=0,u,v;
- FILE *fp;
- char string1[100],string2[100],string2a[100],string3[100],string2b[100];
- char nam[100],type;
- int numread,val,numcolors;
-
- fp=open_to_read_binary(filename);
- if(!fp)
- return(-1);
- fscanf(fp,"%s",string1);
- if(strlen(string1)==1)
- {
- type=string1[0];
- if(type=='l'||type=='a'||type=='m'||
- type=='s'||type=='p'||type=='S')
- {
- M.Type=type;
- numread=fscanf(fp,"%f%f%f%f",&M.Pixsize,&M.Clat,&M.Clon,&M.Space);
- if(numread!=4)
- {
- return(-6);
- }
- }
- }
-
- do
- {
- numread=fscanf(fp,"%s",string1);
- }while(numread>0&&strcmpi(string1,"begin_color")!=0);
- if(numread<1)
- return(-2); /* could not find 'begin_color' */
-
- i=0;
- do
- {
- fscanf(fp,"%s",M.Color_Name[i]);
- if(strcmpi(M.Color_Name[i],"end_color")!=0)
- {
- numread=fscanf(fp,"%s%d%d%d",
- string1,&M.Color_Val[i][0],&M.Color_Val[i][1],&M.Color_Val[i][2]);
- if(strcmpi(M.Color_Name[i],"white")==0)
- {
- M.White=i;
- }
- if(strcmpi(M.Color_Name[i],"black")==0)
- {
- M.Black=i;
- }
- }
- if(numread==4&&M.Out==1&&Fpout)
- fprintf(Fpout,"%20s = %4d%4d%4d\n",M.Color_Name[i],
- M.Color_Val[i][0],M.Color_Val[i][1],M.Color_Val[i][2]);
- i+=1;
- }while(numread==4&&strcmpi(M.Color_Name[i-1],"end_color")!=0&&i<MAX_COLORS);
- numcolors=i;
- do
- {
- numread=fscanf(fp,"%s",string1);
- if(strcmpi(string1,"menu_background")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.Mback=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- if(strcmpi(string1,"text")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.Text=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- if(strcmpi(string1,"highlight")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.High=val;
- else
- {
- printf("'%s %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- if(strcmpi(string1,"background")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.Back=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- if(strcmpi(string1,"graticule")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.Grat=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- if(strcmpi(string1,"lat/lon")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.LatLon=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- if(strcmpi(string1,"black")==0)
- {
- fscanf(fp,"%s%s",string2,string3);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%16s = %s\n",string1,string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- M.Black=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- }
- }while(numread>0&&strcmpi(string1,"begin_vector")!=0);
- if(numread<1)
- return(-3); /* could not find 'begin_vector' */
- i=0;
- do
- {
- numread=fscanf(fp,"%s",M.Group_Name[i]);
- if(numread==1&&strcmpi(M.Group_Name[i],"begin_names")==0)
- {
- do
- {
- numread==fscanf(fp,"%s",String);
- if(strcmpi(String,"end_names")!=0)
- {
- strcpy(PlaceFile[p].name,String);
- fscanf(fp,"%s%s",string1,string2);
- {
- if(strcmpi(string2,"ON")==0)
- PlaceFile[p].on=1;
- else if(strcmpi(string2,"OFF")==0)
- PlaceFile[p].on=0;
- else
- {
- printf("'%s' is not marked ON or OFF\n\n",
- PlaceFile[p].name);
- exit(0);
- }
- }
- fscanf(fp,"%s%f%f%s",
- PlaceFile[p].filename,
- &PlaceFile[p].max_pix,&PlaceFile[p].min_pix,
- string3);
- val=get_color(string3);
- if(val>=0&&val<MAX_COLORS)
- PlaceFile[p].color=val;
- else
- {
- printf("'%s' %s '%s'\n",string1,string2,string3);
- return(-5); /* bad color name */
- }
- for(u=0;u<SYM_SIZE;u++)
- {
- fscanf(fp,"%s",string1);
- if(strlen(string1)!=SYM_SIZE)
- {
- printf("Bad symbol -- must be %d x %d\n",
- Sym_Size,Sym_Size);
- printf("%s %s %f %f %d\n",
- PlaceFile[p].filename,
- PlaceFile[p].max_pix,
- PlaceFile[p].min_pix,
- PlaceFile[p].color);
- return(-12);
- }
- for(v=0;v<SYM_SIZE;v++)
- PlaceFile[p].Symbol[u][v]=string1[v];
- }
- p+=1;
- if(p>=NUM_SYM)
- {
- printf("Too many symbols\n");
- exit(0);
- }
- M.NumSymbol=p;
- }
- }while(strcmpi(String,"end_names")!=0);
- numread=3;
- }
- else if(numread==1&&strcmpi(M.Group_Name[i],"fillin_ihs")==0)
- {
- M.Fill_In=3;
- M.Fill_After=i-1;
- fscanf(fp,"%s%d",String,&M.Num_Fill);
- for(m=0;m<M.Num_Fill;m++)
- {
- fscanf(fp,"%s",M.Fill_In_Name[m]);
- add_disk_path(M.Fill_In_Name[m]);
- numread=fscanf(fp,"%f%f",&M.FI_max[m],&M.FI_min[m]);
- if(numread<2)
- {
- printf("Bad max or min in fill group assignment '%s'\n",
- M.Fill_In_Name[m]);
- exit(0);
- }
- }
- if(numread!=2)
- {
- printf("Could not find max min pixel sizes for fill file\n");
- exit(0);
- }
- do
- {
- fscanf(fp,"%s",string1);
- if(strcmpi(string1,"end")!=0)
- {
- numread=fscanf(fp,"%s%s%s%s",string2,string2a,string2b,string3);
- if(numread<4)
- {
- printf("Error (1) reading fill color %d\n",k+1);
- exit(0);
- }
- if(sscanf(string1,"%d",&k)<1)
- {
- printf("Error (2) reading fill color %d\n",k+1);
- exit(0);
- }
- sscanf(string2,"%f",M.Fill_Color_IHS[k]);
- sscanf(string2a,"%f",M.Fill_Color_IHS[k]+1);
- sscanf(string2b,"%f",M.Fill_Color_IHS[k]+2);
- if(k>M.Max_Fill)
- M.Max_Fill=k;
- M.Fill_Order[n++]=k;
- strcpy(M.Fill_Name[k],string3);
- }
- }while(strcmpi(string1,"end")!=0);
- numread=3;
- }
- else
- {
- if(numread==1&&strcmpi(M.Group_Name[i],"end_vector")!=0)
- {
- numread=fscanf(fp,"%s%d%s",
- string1,&M.Ns[i],string2);
- strcpy(T_Menu_L[i][0],M.Group_Name[i]);
- strcat(T_Menu_L[i][0]," OFF");
- strcpy(T_Menu_L[i][1],M.Group_Name[i]);
- strcat(T_Menu_L[i][1]," ON");
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"\n%s = %d %s \n",M.Group_Name[i],M.Ns[i],string2);
- if(strcmpi(string2,"ON")==0)
- M.Mm[i]=1;
- else
- M.Mm[i]=0;
- if(M.Ns[i]==0||M.Ns[i]>NUM_SIZE)
- {
- printf("Bad M.Ns = %d\n",M.Ns[i]);
- return(-4); /* too many vectors in a group */
- }
- }
- for(k=0;k<M.Ns[i];k++)
- {
- fscanf(fp,"%s%f%f%s",M.MapFile[i][k].filename,
- &M.MapFile[i][k].max_pix,&M.MapFile[i][k].min_pix,
- string1);
- sprintf(nam,"%s.bin",M.MapFile[i][k].filename);
- add_disk_path(nam);
- val=get_color(string1);
- if(val>=0&&val<MAX_COLORS)
- M.MapFile[i][k].color=val;
- else
- {
- printf("'%s' %f %f '%s'\n",
- M.MapFile[i][k].filename,
- M.MapFile[i][k].max_pix,M.MapFile[i][k].min_pix,
- string1);
- return(-5); /* bad color name */
- }
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%20s %8.4f %8.4f %10s = %2d\n",
- M.MapFile[i][k].filename,
- M.MapFile[i][k].max_pix,M.MapFile[i][k].min_pix,
- string1,M.MapFile[i][k].color);
- }
- i+=1;
- }
- }while(numread==3&&strcmpi(M.Group_Name[i-1],"end_vector")!=0&&i<NUM_TYPE);
- i-=1;
- M.Num_Type=i;
- strcpy(T_Menu_L[i+0][0],"all ON");
- strcpy(T_Menu_L[i+0][1],"all ON");
- strcpy(T_Menu_L[i+1][0],"all OFF");
- strcpy(T_Menu_L[i+1][1],"all OFF");
- strcpy(T_Menu_L[i+2][0],"exit");
- strcpy(T_Menu_L[i+2][1],"exit");
- fclose(fp);
- return(1);
- }
-
-
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int get_color(string)
-
- char *string;
-
- {
- int i,j,k;
- int val=-1;
-
- for(i=0;i<MAX_COLORS;i++)
- if(strcmpi(M.Color_Name[i],string)==0)
- return(i);
- return(-1);
- }
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- char Zoom(xc,yc,xs,ys,pixsize,clat,clon,space)
-
- int xc,yc,xs,ys;
- float *pixsize,*clat,*clon,*space;
-
- {
- int i,j,k,k1,k2;
- char ans,ans2;
- int ix[4],iy[4],speed=16;
- float m_ps=*pixsize,m_clon=*clon,m_clat=*clat,m_space=*space;
- float cur_ps=*pixsize/2.0,cur_clon=*clon,cur_clat=*clat,cur_space=*space;
- float cur_scale=1.189207115;
- int cur_ix=xc+xs/2,cur_iy=yc+ys/2;
- double dlat,dlon;
- int txs,screen_xs,lsize=FontSize;
-
- if(VideoType=='S')
- lsize=3;
- if(cur_ps<MIN_PIX)cur_ps=MIN_PIX;
-
- xy_ll((double)cur_ix,(double)cur_iy,&dlat,&dlon);
- cur_clat=dlat;cur_clon=dlon;
- get_corners(xc,yc,xs,ys,m_ps,m_clat,m_clon,cur_ps,cur_clat,cur_clon,ix,iy);
-
- tplotln_val(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0],M.White);
- tplotln_val(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1],M.White);
- tplotln_val(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2],M.White);
- tplotln_val(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3],M.White);
-
- do
- {
- ans=getch();
- if(ans==0)
- {
- ans2=getch();
- if(ans2==59) /* F1 */
- ans='H';
- else
- {
- if(ans2=='G'||ans2=='H'||ans2=='I')cur_iy-=speed;
- if(ans2=='I'||ans2=='M'||ans2=='Q')cur_ix+=speed;
- if(ans2=='O'||ans2=='P'||ans2=='Q')cur_iy+=speed;
- if(ans2=='O'||ans2=='K'||ans2=='G')cur_ix-=speed;
- if(cur_iy<yc)cur_iy=yc;
- if(cur_ix<xc)cur_ix=xc;
- if(cur_iy>yc+ys-1)cur_iy=yc+ys-1;
- if(cur_ix>xc+xs-1)cur_ix=xc+xs-1;
- }
- }
- if(ans=='h'||ans=='H')
- {
- txs=ScreenXs;
- ScreenXs=MaxXs;
- save_box(0,M.Back,Mbuff,
- 0,0,MaxXs,32/lsize);
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,32/lsize);
- sprintf(String,
- "(s)maller (l)arger 'Enter'=plot 'Esc'=exit without plotting");
- plot_font_h(M.White,1,1,String,FontSize,Font);
- ans=getch();
- unsave_box(0,M.Back,Mbuff,
- 0,0,MaxXs,32/lsize);
- ScreenXs=txs;
- }
-
- if(ans=='l')cur_ps*=cur_scale;
- if(ans=='s')cur_ps/=cur_scale;
- if(cur_ps<MIN_PIX)cur_ps=MIN_PIX;
- if(ans=='-')
- {
- if(speed>1)
- speed/=2;
- else
- cur_scale=sqrt((double)cur_scale);
- }
- if(ans=='+'&&speed<256)speed*=2;
-
- unplotln(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0]);
- unplotln(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1]);
- unplotln(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2]);
- unplotln(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3]);
-
- xy_ll((double)cur_ix,(double)cur_iy,&dlat,&dlon);
- cur_clat=dlat;cur_clon=dlon;
- get_corners(xc,yc,xs,ys,
- m_ps,m_clat,m_clon,cur_ps,cur_clat,cur_clon,ix,iy);
-
- tplotln_val(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0],M.White);
- tplotln_val(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1],M.White);
- tplotln_val(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2],M.White);
- tplotln_val(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3],M.White);
-
- }while(ans!=83&&ans!=27&&ans!=13);
-
- unplotln(0,ix[0],iy[0]+1,ix[1],iy[1],MT_Buff[0]);
- unplotln(0,ix[1]+1,iy[1],ix[2],iy[2],MT_Buff[1]);
- unplotln(0,ix[2],iy[2]-1,ix[3],iy[3],MT_Buff[2]);
- unplotln(0,ix[3]-1,iy[3],ix[0],iy[0],MT_Buff[3]);
-
- M.Pixsize=*pixsize=cur_ps;
- M.Clat=*clat=cur_clat;
- M.Clon=*clon=cur_clon;
-
- if(cur_ps<20)
- {
- *space=30.0;
- return(ans);
- }
- if(cur_ps<10)
- {
- *space=15.0;
- return(ans);
- }
- if(cur_ps<2)
- {
- *space=5.0;
- return(ans);
- }
- *space=1.0;
- return(ans);
-
- }
-
-
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- void get_corners(xc,yc,xs,ys,m_pixsize,m_clat,m_clon,
- cur_pixsize,cur_clat,cur_clon,x,y)
-
- int xc,yc,xs,ys;
- float m_pixsize,m_clat,m_clon,cur_pixsize,cur_clat,cur_clon;
- int x[4],y[4];
-
- {
- int i,j,k;
- double lat[4],lon[4],dx,dy;
-
- miv.indat[0]=cur_pixsize;
- miv.indat[1]=cur_clat;
- miv.indat[2]=cur_clon;
- miv.indat[3]=cur_clon;
- miv.indat[4]=cur_clat+10;
- miv.indat[5]=cur_clat-10;
- map_pos.xc=xc;
- map_pos.yc=yc;
- map_pos.xs=xs;
- map_pos.ys=ys;
- auto_set_cc(miv.type,miv.indat);
-
- xy_ll((double)xc,(double)yc,lat+0,lon+0);
- xy_ll((double)xc,(double)yc+ys-1,lat+1,lon+1);
- xy_ll((double)xc+xs-1,(double)yc+ys-1,lat+2,lon+2);
- xy_ll((double)xc+xs-1,(double)yc,lat+3,lon+3);
-
- miv.indat[0]=m_pixsize;
- miv.indat[1]=m_clat;
- miv.indat[2]=m_clon;
- miv.indat[3]=m_clon;
- miv.indat[4]=m_clat+10;
- miv.indat[5]=m_clat-10;
- map_pos.xc=xc;
- map_pos.yc=yc;
- map_pos.xs=xs;
- map_pos.ys=ys;
- auto_set_cc(miv.type,miv.indat);
-
- for(i=0;i<4;i++)
- {
- ll_xy(&dx,&dy,lat[i],lon[i]);
- x[i]=dx;
- y[i]=dy;
- }
- }
-
-
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- int plot_map(xc,yc,xs,ys,pixsize,clat,clon,space,iop)
-
- int xc,yc,xs,ys,iop;
- float pixsize,clat,clon,space;
-
- {
- int i,j,k,l,m;
- double sp=space;
- int num,val,filled=0;
- int ix=ScreenXs/2,iy=ScreenYs/2,speed=16;
-
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"\npixsize = %6.3f clat = %12.5f clon = %12.5f\n",
- pixsize,clat,clon);
-
- miv.type=M.Type;
- miv.indat[0]=pixsize;
- miv.indat[1]=clat;
- miv.indat[2]=clon;
- miv.indat[3]=clon;
- miv.indat[4]=clat+10;
- miv.indat[5]=clat-10;
- map_pos.xc=xc;
- map_pos.yc=yc;
- map_pos.xs=xs;
- map_pos.ys=ys;
- auto_set_cc(miv.type,miv.indat);
- screen_mm();
-
- if(iop==0)
- {
- paint_box(0,M.Back,MT_Buff,0,0,ScreenXs,ScreenYs);
- if(pixsize>5.0)
- {
- sp=10;
- if(M.Fill_In==0)
- plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize>2.5&&pixsize<=5.0)
- {
- sp=5;
- if(M.Fill_In==0)
- plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=2.5&&pixsize>0.5)
- {
- sp=1;
- if(M.Fill_In==0)
- plot_graticule(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.5&&pixsize>0.25)
- {
- sp=0.5;
- if(M.Fill_In==0)
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.25&&pixsize>0.05)
- {
- sp=0.1;
- if(M.Fill_In==0)
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.05&&pixsize>0.025)
- {
- sp=0.05;
- if(M.Fill_In==0)
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.025&&pixsize>0.005)
- {
- sp=0.01;
- if(M.Fill_In==0)
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.005&&pixsize>0.0025)
- {
- sp=0.005;
- if(M.Fill_In==0)
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(pixsize<=0.0025)
- {
- sp=0.001;
- if(M.Fill_In==0)
- plot_graticule_frac(Font,M.Grat,M.LatLon,sp,M.GratOn);
- }
- if(iop==0)
- {
- for(i=0;i<M.Num_Type;i++)
- {
- for(j=0;j<M.Ns[i];j++)
- {
- if(M.MapFile[i][j].max_pix*PixScale>pixsize
- &&M.MapFile[i][j].min_pix*PixScale<=pixsize
- &&M.Mm[i]==1)
- {
- if(kbhit()>0)
- {
- val=getch();
- if(val==27)
- return(-1);
- }
- num=convert_bin(M.MapFile[i][j].color,
- M.MapFile[i][j].filename);
- if(num<-1)
- return(-2);
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"%s -- color = %d plotted %d segments\n",
- M.MapFile[i][j].filename,M.MapFile[i][j].color,num);
- }
- }
- if(M.Fill_In>0&&i==M.Fill_After&&M.Mm[i]==1)
- {
- filled=0;
- for(m=0;m<M.Num_Fill;m++)
- {
- if(M.FI_max[m]*PixScale>pixsize&&
- M.FI_min[m]*PixScale<=pixsize)
- {
- num=fill_in_area(M.Fill_In_Name[m]);
- if(num<-1)
- return(-2);
- filled=1;
- }
- }
- if(filled==1)
- {
- save_box(0,M.Black,Mbuff,0,0,MaxXs,36/FontSize);
- sprintf(String,
- "You are in 'cursor mode', hit any key to continue or F1 for help.");
- plot_font_h(M.White,10/FontSize,5/FontSize,String,FontSize,Font);
- if(getch()==0)
- getch();
- unsave_box(0,M.Black,Mbuff,0,0,MaxXs,36/FontSize);
- pix_loc(ix,iy,&ix,&iy,&speed);
- }
- }
- }
- for(i=0;i<M.NumSymbol;i++)
- {
- if(PlaceFile[i].on==1&&
- pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
- {
- symbol_plot(i,0);
- }
- }
- }
- }
- }
-
- /**************************************************************************
- **
- ** iop = 0 -- plot only symbols
- ** 1 -- names
- ** 2 -- id
- **
- ************************************************************************* */
-
- int symbol_plot(i,iop)
-
- int i,iop;
-
- {
- int j,k,u,v;
- int val;
- FILE *fploc;
- char string[STR_LEN],id[STR_LEN],name[STR_LEN];
- double lat,lon,x,y;
- int ix,iy,ss=SYM_SIZE/2;
- char *result;
-
- fploc=open_to_read_binary(PlaceFile[i].filename);
- if(fploc)
- {
- while((result=fgets(string,80,fploc))!=NULL)
- {
- string[strlen(string)-1]='\0';
- if(sscanf(string,"%s%lf%lf%s",name,&lat,&lon,id)!=4)
- {
- fclose(fploc);
- return(-1);
- }
- ll_xy(&x,&y,lat,lon);
- ix=x,iy=y;
- if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs)
- {
- if(iop==0)
- {
- for(u=0;u<SYM_SIZE;u++)
- {
- for(v=0;v<SYM_SIZE;v++)
- {
- if(PlaceFile[i].Symbol[u][v]=='*')
- plotpt(0,ix-ss+v,iy-ss+u,PlaceFile[i].color);
- }
- }
- }
- if(iop==1)
- plot_font_h(M.White,ix-ss-strlen(name)*7,
- iy-ss+2,name,2,Font);
- if(iop==2)
- plot_font_h(M.White,ix+ss+2,iy-ss+2,id,2,Font);
- }
- }
- }
- fclose(fploc);
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int fill_in_area(filename)
-
- char *filename;
-
- {
- int i,j,k,p;
- int idc[2],val1,val2;
- double lat,lon;
- FILE *fpblb;
- double x,y;
- int ix,iy,num;
- char pth[STR_LEN],nam[10],typ[10],string[STR_LEN];
-
- fpblb=open_to_read_binary(filename);
- split(filename,pth,nam,typ);
- if(!fpblb)
- return(0);
- while(fread((char *)idc,sizeof(int),2,fpblb)==2)
- {
- fread((char *)&lat,sizeof(double),1,fpblb);
- fread((char *)&lon,sizeof(double),1,fpblb);
- ll_xy(&x,&y,lat,lon);
- ix=x;iy=y;
- if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs)
- {
- if(getpt(0,ix,iy)==M.Back)
- {
- if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
- {
- num=auto_fill_in(0,idc[1]+16,Mbuff,todo,ix,iy);
- if(num<-1)
- return(-2);
- }
- else
- {
- val1=M.Fill_Color[idc[1]][0];
- val2=M.Fill_Color[idc[1]][1];
- if(val1==M.Back)
- val1=M.Black;
- if(val2==M.Back)
- val2=M.Black;
- num=auto_fill_in_2(0,val1,val2,Mbuff,todo,ix,iy);
- if(num<-1)
- return(-2);
- }
- }
- else if(getpt(0,ix,iy)!=idc[1]+16)
- {
- if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
- plotpt(0,ix,iy,idc[1]+16);
- else
- {
- if((ix+iy)%2==0)
- {
- val1=M.Fill_Color[idc[1]][0];
- plotpt(0,ix,iy,val1);
- }
- else
- {
- val2=M.Fill_Color[idc[1]][1];
- plotpt(0,ix,iy,val2);
- }
- }
- }
- }
- }
- fclose(fpblb);
- return(1);
- }
-
-
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- void save_rectangle(xc,yc,xs,ys,fp)
-
- int xc,yc,xs,ys;
- FILE *fp;
-
- {
- int i,j,k;
-
- rewind(fp);
-
- fwrite((char *)&ys,sizeof(int),1,fp);
- fwrite((char *)&xs,sizeof(int),1,fp);
- for(i=0;i<ys;i++)
- {
- getrow(0,xc,xc+xs-1,i+yc,MT_Buff);
- fwrite((char *)MT_Buff,sizeof(char),xs,fp);
- }
- }
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- void recall_rectangle(xc,yc,xs,ys,fp)
-
- int xc,yc,xs,ys;
- FILE *fp;
-
- {
- int i,j,k;
-
- rewind(fp);
- fread((char *)&ys,sizeof(int),1,fp);
- fread((char *)&xs,sizeof(int),1,fp);
- if(xc+xs>ScreenXs)xc=ScreenXs-xs;
- if(yc+ys>ScreenYs)yc=ScreenYs-ys;
- if(xc<0||yc<0)return;
-
- for(i=0;i<ys;i++)
- {
- fread((char *)MT_Buff,sizeof(char),xs,fp);
- plotrow(1,xc,xc+xs-1,i+yc,MT_Buff);
- }
- }
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- void screen_mm()
-
- {
- double lat,lon,x,y;
- double sx=ScreenXs,sy=ScreenYs;
- float flat,flon,lon_r,lon_l;
-
- MaxLat=-360.0;
- MaxLon=-360.0;
- MinLat= 360.0;
- MinLon= 360.0;
-
- x=0.0;y=0.0;
- xy_ll(x,y,&lat,&lon);
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=0.0;y=ScreenYs/2.0;
- xy_ll(x,y,&lat,&lon);lon_l=lon;
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=0.0;y=ScreenYs;
- xy_ll(x,y,&lat,&lon);
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=320.0;y=ScreenYs;
- xy_ll(x,y,&lat,&lon);
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=ScreenXs;y=ScreenYs;
- xy_ll(x,y,&lat,&lon);
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=ScreenXs;y=ScreenXs/2;
- xy_ll(x,y,&lat,&lon);lon_r=lon;
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=ScreenXs;y= 0.0;
- xy_ll(x,y,&lat,&lon);
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- x=ScreenXs/2;y= 0.0;
- xy_ll(x,y,&lat,&lon);
- flat=lat;flon=lon;
- if(flat>MaxLat)MaxLat=flat;
- if(flon>MaxLon)MaxLon=flon;
- if(flat<MinLat)MinLat=flat;
- if(flon<MinLon)MinLon=flon;
- if(lon_l>180.0)
- lon_l-=360.0;
- if(lon_r>180.0)
- lon_r-=360.0;
-
- lat=-89.999; /* south pole check */
- ll_xy(&x,&y,lat,lon);
- if(x>=0.0&&x<sx&&y>0.0&&y<sy)
- {
- MinLat=-90.001;
- MinLon=-360.0;
- MaxLon= 360.0;
- }
- lat=89.999; /* north pole check */
- ll_xy(&x,&y,lat,lon);
- if(x>=0.0&&x<sx&&y>0.0&&y<sy)
- {
- MaxLat= 90.001;
- MinLon=-360.0;
- MaxLon= 360.0;
- }
- if(lon_l>lon_r) /* date line on screen */
- {
- MinLon=-360.0;
- MaxLon= 360.0;
- }
- }
-
-
- /***********************************************************************
- **
- **
- **
- ***********************************************************************/
- int auto_fill_in(hue,val,buffer,todo,cx,cy)
-
- int todo[2][MAXDO];
- int hue,val;
- unsigned char *buffer;
- int cx,cy;
-
- {
- int i,j,k,m,n,l;
- int x=cx,y=cy,on=0;
- int lastup[2],lastdn[2];
- int fillval,cval,kbval;
-
- fillval=getpt(hue,x,y);
- if(fillval==val)return(-1);
-
- do
- {
- if(kbhit()>0)
- {
- kbval=getch();
- if(kbval==27)
- return(-2);
- }
- lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
- for(i=x;i<ScreenXs;i++)
- {
- if(i>=ScreenXs||getpt(hue,i,y)!=fillval)
- break;
- plotpt(hue,i,y,val);
- on=check_point(hue,i,y,fillval,on,todo);
- if(y>0&&getpt(hue,i,y-1)==fillval)
- {
- lastup[0]=i;
- lastup[1]=y-1;
- }
- if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
- {
- lastdn[0]=i;
- lastdn[1]=y+1;
- }
- }
- if(lastup[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastup[0];
- todo[1][on]=lastup[1];
- on+=1;
- }
- if(lastdn[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastdn[0];
- todo[1][on]=lastdn[1];
- on+=1;
- }
- lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
- if(x>0)
- {
- for(i=x-1;i>=0;i--)
- {
- if(i<0||getpt(hue,i,y)!=fillval)
- break;
- plotpt(hue,i,y,val);
- on=check_point(hue,i,y,fillval,on,todo);
- if(y>0&&getpt(hue,i,y-1)==fillval)
- {
- lastup[0]=i;
- lastup[1]=y-1;
- }
- if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
- {
- lastdn[0]=i;
- lastdn[1]=y+1;
- }
- }
- }
- if(lastup[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastup[0];
- todo[1][on]=lastup[1];
- on+=1;
- }
- if(lastdn[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastdn[0];
- todo[1][on]=lastdn[1];
- on+=1;
- }
- on=purge(hue,fillval,todo,on);
- if(on>0)
- {
- x=todo[0][on-1];
- y=todo[1][on-1];
- }
- }while(on>0);
- }
-
- /***********************************************************************
- **
- **
- **
- ***********************************************************************/
-
- int auto_fill_in_2(hue,val1,val2,buffer,todo,cx,cy)
-
- int todo[2][MAXDO];
- int hue,val1,val2;
- unsigned char *buffer;
- int cx,cy;
-
- {
- int i,j,k,m,n,l;
- int x=cx,y=cy,on=0;
- int lastup[2],lastdn[2];
- int fillval,cval,kbval;
-
- fillval=getpt(hue,x,y);
- if(fillval==val1||fillval==val2)
- return(-1);
- do
- {
- if(kbhit()>0)
- {
- kbval=getch();
- if(kbval==27)
- return(-2);
- }
- lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
- for(i=x;i<ScreenXs;i++)
- {
- if(i>=ScreenXs||getpt(hue,i,y)!=fillval)
- break;
- if(((i+y)%2)==0)
- plotpt(hue,i,y,val1);
- else
- plotpt(hue,i,y,val2);
- on=check_point(hue,i,y,fillval,on,todo);
- if(y>0&&getpt(hue,i,y-1)==fillval)
- {
- lastup[0]=i;
- lastup[1]=y-1;
- }
- if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
- {
- lastdn[0]=i;
- lastdn[1]=y+1;
- }
- }
- if(lastup[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastup[0];
- todo[1][on]=lastup[1];
- on+=1;
- }
- if(lastdn[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastdn[0];
- todo[1][on]=lastdn[1];
- on+=1;
- }
- lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
- if(x>0)
- {
- for(i=x-1;i>=0;i--)
- {
- if(i<0||getpt(hue,i,y)!=fillval)
- break;
- if(((i+y)%2)==0)
- plotpt(hue,i,y,val1);
- else
- plotpt(hue,i,y,val2);
- on=check_point(hue,i,y,fillval,on,todo);
- if(y>0&&getpt(hue,i,y-1)==fillval)
- {
- lastup[0]=i;
- lastup[1]=y-1;
- }
- if(i<ScreenXs-1&&getpt(hue,i,y+1)==fillval)
- {
- lastdn[0]=i;
- lastdn[1]=y+1;
- }
- }
- }
- if(lastup[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastup[0];
- todo[1][on]=lastup[1];
- on+=1;
- }
- if(lastdn[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastdn[0];
- todo[1][on]=lastdn[1];
- on+=1;
- }
- on=purge(hue,fillval,todo,on);
- if(on>0)
- {
- x=todo[0][on-1];
- y=todo[1][on-1];
- }
- }while(on>0);
- }
-
-
- /***********************************************************************
- **
- **
- **
- ***********************************************************************/
-
- int convert_bin(val,region)
-
- char *region;
- int val;
-
- {
- int i,j,k,m,n=0,p;
- double x,y,xo,yo;
- int ix,iy,ixo=-1,iyo=-1;
- double dx,dy,dist;
- int secnum,numpt,numsec,ival;
- FILE *fp,*fphdr,*fpatr;
- float latlon[2],mll[4],mnln,mxln,mnlt,mxlt;
- char string[40],pth[40],name[40],type[40];
- int doit,numplot=0;
- int first_seg=-1,last_seg=-1,atr=1;
- long offset,attrib;
-
- strcpy(string,region);
- strcat(string,".bin");
- fp=open_to_read_binary(string);
- if(!fp)
- {
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"could not open '%s'\n",string);
- return(-1);
- }
- /* setbuf(fp,Inbuff);*/
- strcpy(string,region);
- strcat(string,".hdr");
- fphdr=open_to_read_binary(string);
- if(!fphdr)
- {
- if(M.Out==1&&Fpout)
- fprintf(Fpout,"could not open '%s'\n",string);
- fclose(fp);
- return(-1);
- }
- /* setbuf(fphdr,Inbuff2);*/
- fread((char *)&numsec,sizeof(int),1,fphdr);
- fread((char *)&numsec,sizeof(int),1,fp);
- for(j=0;j<numsec;j++)
- {
- if(kbhit()>0)
- {
- ival=getch();
- if(ival==27)
- {
- fclose(fp);
- fclose(fphdr);
- return(-2);
- }
- }
- fread((char *)&offset,sizeof(long),1,fphdr);
- fread((char *)mll,sizeof(float),4,fphdr);
- doit=1;
- mnln=mll[0];mxln=mll[1];mnlt=mll[2];mxlt=mll[3];
- if(mnln>MaxLon||mnlt>MaxLat||mxln<MinLon||mxlt<MinLat)
- doit=0;
- if(doit==1)
- {
- numplot+=1;
- fseek(fp,offset,SEEK_SET);
- fread((char *)&numpt,sizeof(int),1,fp);
- fread((char *)mll,sizeof(float),4,fp);
- m=0;
- for(i=0;i<numpt;i++)
- {
- fread((char *)latlon,sizeof(float),2,fp);
- if(doit==1)
- {
- ll_xy(&x,&y,(double)latlon[0],(double)latlon[1]);
- if(i==0)
- {
- xo=x;yo=y;
- ixo=ix;iyo=iy;
- }
- ix=x;iy=y;
- dist=(xo-x)*(xo-x)+(yo-y)*(yo-y);
- if(dist<1000000.0)
- {
- plotpt(0,ix,iy,val);
- if(i>0)
- plotln(0,ix,iy,ixo,iyo,val);
- ixo=ix;iyo=iy;
- xo=ix;yo=iy;
- }
- }
- }
- }
- }
- fclose(fp);
- fclose(fphdr);
- return(numplot);
- }
-
- /**************************************************************************
- **
- **
- **
- ************************************************************************* */
-
- int split(string,path,name,type)
-
- char *string,*path,*name,*type;
-
- {
- int i,j,k;
- int dot=-1,last_slash=-1,len=strlen(string),num=0;
-
- if(strlen(string)>STR_LEN)
- {
- SetVideoMode(0,&B_Id);
- printf("In split() -- string 1 too long!\n\n");
- exit(0);
- }
-
- for(i=0;i<len;i++)
- {
- if(string[i]=='.')
- dot=i;
- if(string[i]=='\\')
- last_slash=i;
- }
- last_slash+=1;
- if(dot==-1)
- dot=len-1;
- if(last_slash>0)
- {
- for(i=0;i<last_slash;i++)
- path[i]=string[i];
- }
- path[last_slash]='\0';
- for(i=last_slash;i<dot;i++)
- name[i-last_slash]=string[i];
- name[dot-last_slash]='\0';
- dot+=1;
- for(i=dot;i<len;i++)
- type[i-dot]=string[i];
- type[len-dot]='\0';
- if(strlen(name)>0)
- num+=1;
- if(strlen(type)>0)
- num+=1;
-
- return(num);
- }
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- void fill_voids()
-
- {
- int i,j,k;
- int val;
- int xc=240,yc=240,xs=32,ys=32;
- int x1=xc-1,x2=xc+xs,speed=8;
- int num,min;
-
- if(x1<0)x1=0;
- if(x2>ScreenXs-1)x2=ScreenXs-1;
-
- printf("Give minimum number of neighbors to fill with.\n");
- scanf("%d",&min);
-
- do
- {
- limit_area(&xc,&yc,&xs,&ys,&speed,ScreenXs,1,MT_Buff);
-
- for(i=yc;i<yc+2;i++) /* load first 2 rows */
- getrow(0,xc,xc+xs-1,i,MT_Buff[i%3]);
- for(i=yc+1;i<yc+ys-1;i++)
- {
- getrow(0,xc,xc+xs-1,i+1,MT_Buff[(i+1)%3]);
- MT_Buff[3][0]=MT_Buff[i%3][0];
- MT_Buff[3][xs-1]=MT_Buff[i%3][xs-1];
- for(j=1;j<xs-1;j++)
- {
- if(MT_Buff[i%3][j]==0)
- {
- num=0;
- if(MT_Buff[(i-1)%3][j-1]!=0)num+=1;
- if(MT_Buff[(i-1)%3][j]!=0)num+=1;
- if(MT_Buff[(i-1)%3][j+1]!=0)num+=1;
- if(MT_Buff[(i)%3][j-1]!=0)num+=1;
- if(MT_Buff[(i)%3][j+1]!=0)num+=1;
- if(MT_Buff[(i+1)%3][j-1]!=0)num+=1;
- if(MT_Buff[(i+1)%3][j]!=0)num+=1;
- if(MT_Buff[(i+1)%3][j+1]!=0)num+=1;
-
- if(num>=min)
- {
- if(MT_Buff[(i-1)%3][j+1]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j+1];
- else if(MT_Buff[(i-1)%3][j]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j];
- else if(MT_Buff[i%3][j+1]!=0)
- MT_Buff[3][j]=MT_Buff[i%3][j+1];
- else if(MT_Buff[(i-1)%3][j-1]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
- else if(MT_Buff[(i+1)%3][j+1]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
- else if(MT_Buff[(i)%3][j-1]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
- else if(MT_Buff[(i+1)%3][j]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
- else if(MT_Buff[(i+1)%3][j-1]!=0)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
- }
- }
- else
- MT_Buff[3][j]=MT_Buff[i%3][j];
- }
- plotrow(0,xc,xc+xs-1,i,MT_Buff[3]);
- }
- printf("Again?\n");
- }while(getch()!='n');
- }
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- void remove_boundaries(val)
-
- int val;
-
- {
- int i,j,k;
- int xc=0,yc=0,xs=ScreenXs,ys=ScreenYs;
- int x1=xc-1,x2=xc+xs;
-
- if(x1<0)x1=0;
- if(x2>ScreenXs-1)x2=ScreenXs-1;
-
- for(i=yc;i<yc+2;i++) /* load first 2 rows */
- getrow(0,xc,xc+xs-1,i,MT_Buff[i%3]);
- for(i=yc+1;i<yc+ys-1;i++)
- {
- getrow(0,xc,xc+xs-1,i+1,MT_Buff[(i+1)%3]);
- MT_Buff[3][0]=MT_Buff[i%3][0];
- MT_Buff[3][xs-1]=MT_Buff[i%3][xs-1];
- for(j=1;j<xs-1;j++)
- {
- if(MT_Buff[i%3][j]==val)
- {
- if(MT_Buff[(i-1)%3][j+1]!=val)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j+1];
- else if(MT_Buff[(i-1)%3][j]!=val)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j];
- else if(MT_Buff[i%3][j+1]!=val)
- MT_Buff[3][j]=MT_Buff[i%3][j+1];
- else if(MT_Buff[(i-1)%3][j-1]!=val)
- MT_Buff[3][j]=MT_Buff[(i-1)%3][j-1];
- }
- else
- MT_Buff[3][j]=MT_Buff[i%3][j];
- }
- plotrow(0,xc,xc+xs-1,i,MT_Buff[3]);
- }
- }
-
-
- /***********************************************************************
- **
- **
- **
- ***********************************************************************/
-
- int fill_in(hue,val,buffer,todo,cx,cy,speed)
-
- int todo[2][MAXDO];
- int hue,val;
- unsigned char *buffer;
- int *cx,*cy,*speed;
-
- {
- int i,j,k,m,n;
- int x=*cx,y=*cy,on=0;
- int lastup[2],lastdn[2];
- int fillval,cval;
-
- pix_loc(x,y,&x,&y,speed);
- *cx=x;*cy=y;
-
- fillval=getpt(hue,x,y);
- printf("starting at point %d,%d filling all %d pixels\n",x,y,fillval);
-
- on=check_point(hue,x,y,fillval,on,todo);
-
- do
- {
- lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
- for(i=x;i<ScreenXs;i++)
- {
- if(getpt(hue,i,y)!=fillval)
- break;
- plotpt(hue,i,y,val);
- on=check_point(hue,i,y,fillval,on,todo);
- if(getpt(hue,i,y-1)==fillval)
- {
- lastup[0]=i;
- lastup[1]=y-1;
- }
- if(getpt(hue,i,y+1)==fillval)
- {
- lastdn[0]=i;
- lastdn[1]=y+1;
- }
- }
- if(lastup[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastup[0];
- todo[1][on]=lastup[1];
- on+=1;
- }
- if(lastdn[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastdn[0];
- todo[1][on]=lastdn[1];
- on+=1;
- }
- lastup[0]=lastup[1]=lastdn[0]=lastdn[1]=-1;
- for(i=x-1;i>=0;i--)
- {
- if(getpt(hue,i,y)!=fillval)
- break;
- plotpt(hue,i,y,val);
- on=check_point(hue,i,y,fillval,on,todo);
- if(y>0&&getpt(hue,i,y-1)==fillval)
- {
- lastup[0]=i;
- lastup[1]=y-1;
- }
- if(getpt(hue,i,y+1)==fillval)
- {
- lastdn[0]=i;
- lastdn[1]=y+1;
- }
- }
- if(lastup[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastup[0];
- todo[1][on]=lastup[1];
- on+=1;
- }
- if(lastdn[0]>=0&&on<MAXDO)
- {
- todo[0][on]=lastdn[0];
- todo[1][on]=lastdn[1];
- on+=1;
- }
- on=purge(hue,fillval,todo,on);
- do
- {
- on-=1;
- x=todo[0][on];
- y=todo[1][on];
- }while(getpt(hue,x,y)!=fillval&&on>0);
-
- }while(on>0);
- }
-
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- int purge(hue,fillval,todo,on)
-
- int hue,fillval,todo[2][MAXDO],on;
-
- {
- int i,j,k;
-
- k=0;
- for(i=0;i<on;i++)
- {
- if(getpt(hue,todo[0][i],todo[1][i])==fillval)
- {
- todo[0][k]=todo[0][i];
- todo[1][k]=todo[1][i];
- k+=1;
- }
- }
- return(k);
- }
-
-
-
-
-
- /********************************************************************
- **
- **
- **
- ********************************************************************* */
-
- int check_point(hue,x,y,fillval,on,todo)
-
- int hue,x,y,fillval,on,todo[2][MAXDO];
-
- {
- if(on>=MAXDO)return(on);
-
- if(getpt(hue,x,y-1)==fillval&&y>0&&x>0&&x<ScreenXs-1)
- {
- if(getpt(hue,x-1,y-1)!=fillval||getpt(hue,x+1,y-1)!=fillval)
- {
- todo[0][on]=x;
- todo[1][on]=y-1;
- on+=1;
- }
- }
- if(on>=MAXDO)return(on);
-
- if(getpt(hue,x,y+1)==fillval&&y<ScreenYs-1&&x>0&&x<ScreenXs-1)
- {
- if(getpt(hue,x-1,y+1)!=fillval||getpt(hue,x+1,y+1)!=fillval)
- {
- todo[0][on]=x;
- todo[1][on]=y+1;
- on+=1;
- }
- }
- return(on);
- }
-
-
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- int search_points(cx,cy,pixsize,outstring)
-
- int *cx,*cy;
- float pixsize;
- char *outstring;
-
- {
- int i,j,k;
- int ix,iy;
- double dcx=*cx,dcy=*cy,dx,dy,dist,mindist=1000000000,lat,lon;
- FILE *fploc;
- char string[STR_LEN],id[STR_LEN],id1[STR_LEN],*result;
- int numpoints=0;
-
- outstring[0]='\0';
- for(i=0;i<M.NumSymbol;i++)
- {
- if(PlaceFile[i].on==1&&
- pixsize>=PlaceFile[i].min_pix&&pixsize<PlaceFile[i].max_pix)
- {
- fploc=open_to_read_binary(PlaceFile[i].filename);
- if(fploc!=NULL)
- {
- while((result=fgets(string,80,fploc))!=NULL&&strlen(string)>4)
- {
- string[strlen(string)-1]='\0';
- if(sscanf(string,"%s%lf%lf%s",id1,&lat,&lon,id)!=4)
- {
- fclose(fploc);
- break;
- }
- ll_xy(&dx,&dy,lat,lon);
- ix=dx,iy=dy;
- if(ix>=0&&ix<ScreenXs&&iy>=0&&iy<ScreenYs&&
- strlen(string)<STR_LEN)
- {
- dist=(dx-dcx)*(dx-dcx)+(dy-dcy)*(dy-dcy);
- if(dist<mindist)
- {
- *cx=ix;*cy=iy;
- mindist=dist;
- strcpy(outstring,string);
- numpoints+=1;
- }
- }
- }
- }
- fclose(fploc);
- }
- }
- return(numpoints);
- }
-
-
-
-
- /***********************************************************************
- **
- **
- **
- **
- ************************************************************************/
-
- int set_back()
-
- {
- int i,j,k;
- float r,g,b;
- float max=0.0;
-
- for(i=0;i<256;i++)
- {
- lutc[i].r=M.lut[i].r;
- lutc[i].g=M.lut[i].g;
- lutc[i].b=M.lut[i].b;
- }
- for(i=15;i<256;i++)
- {
- r=M.lut[i].r;
- g=M.lut[i].g;
- b=M.lut[i].b;
- if(r>max)max=r;
- if(g>max)max=g;
- if(b>max)max=b;
- }
- if(255.0/max<BackBright)
- BackBright=255.0/max;
- for(i=16;i<256;i++)
- {
- r=M.lut[i].r;
- g=M.lut[i].g;
- b=M.lut[i].b;
- lutc[i].r=r*BackBright;
- lutc[i].g=g*BackBright;
- lutc[i].b=b*BackBright;
- }
- WritePalette(lutc);
- }
-
-
- /**************************************************************************
- **
- **
- **
- **
- ***************************************************************************/
-
- int plot_key(xc,yc,size)
-
- int xc,yc,size;
-
- {
- int i,j,k,l;
- int high=30/size,wide=0;
- int marg=6/size,val[2];
- unsigned char buffer[100];
- int x1=xc,y1=yc,color,twide;
-
- M.KeyPlotted=1;
- for(k=1;k<=M.Max_Fill;k++)
- if(strlen(M.Fill_Name[k])>wide)
- wide=strlen(M.Fill_Name[k]);
- wide=(wide+1)*15/size;
- twide=((M.Max_Fill-1)/(ScreenYs/high)+1)*wide;
- if(xc+twide>ScreenXs)
- x1=ScreenXs-twide;
- paint_box(0,M.Back,MT_Buff,x1,yc,twide,ScreenYs);
- for(i=1;i<=M.Max_Fill;i++)
- {
- k=M.Fill_Order[i];
- if(VideoType=='X'||VideoType=='S'||VideoType=='Y')
- {
- val[0]=val[1]=k+16;
- }
- else
- {
- val[0]=M.Fill_Color[k][0];
- val[1]=M.Fill_Color[k][1];
- }
- for(j=0;j<wide+1;j++)
- buffer[j]=val[j%2];
- for(l=0;l<high;l++)
- plotrow(0,x1,x1+wide-1,l+y1,buffer+(l%2));
- color=M.Comp_Color[k+16];
- if(strlen(M.Fill_Name[k])>0)
- plot_font_h(color,x1+marg,y1+marg,
- M.Fill_Name[k],size,Font);
- y1+=high;
- if(y1+high>ScreenYs)
- {
- y1=yc;
- x1+=wide;
- }
- }
- ScreenXs-=twide;
- }
-
-
- /********************************************************************
- **
- ** type g -- grey all lut[] files
- ** G -- grey only lut[]
- ** i -- initial header map
- ** r -- reset lut[] to lutc[]
- **
- ** iop == 1 don't print RGB etc.
- **
- **
- ********************************************************************* */
-
- void set_lut(type,iop)
-
- char type;
- int iop;
-
- {
- int k,hue,brite,j,m,n;
- int color[3],h;
- double dbrite,dval;
- float val,minval,i,s,rgb[3];
- int c1,c2;
- long mindist,dist,r,g,b,r0,g0,b0;
-
- /*
- if(type=='g')
- {
- M.lut[ 0].r= 0;
- M.lut[ 0].g= 0;
- M.lut[ 0].b= 0;
- M.lut[ 1].r= 46;
- M.lut[ 1].g= 46;
- M.lut[ 1].b= 46;
- M.lut[ 2].r=128;
- M.lut[ 2].g=128;
- M.lut[ 2].b=128;
- M.lut[ 3].r=255;
- M.lut[ 3].g=255;
- M.lut[ 3].b=255;
- }
- */
- if(type=='c')
- {
- for(k=0;k<MAX_COLORS;k++)
- {
- M.lut[ k].r=M.Color_Val[k][0];
- M.lut[ k].g=M.Color_Val[k][1];
- M.lut[ k].b=M.Color_Val[k][2];
- }
- for(k=MAX_COLORS;k<256;k++)
- {
- M.lut[ k].r=k;
- M.lut[ k].g=k;
- M.lut[ k].b=k;
- }
- if(M.Fill_In==1)
- {
- for(k=0;k<=M.Max_Fill;k++)
- {
- M.lut[k+16].r=(M.Color_Val[M.Fill_Color[k][0]][0]+
- M.Color_Val[M.Fill_Color[k][1]][0])/2;
- M.lut[k+16].g=(M.Color_Val[M.Fill_Color[k][0]][1]+
- M.Color_Val[M.Fill_Color[k][1]][1])/2;
- M.lut[k+16].b=(M.Color_Val[M.Fill_Color[k][0]][2]+
- M.Color_Val[M.Fill_Color[k][1]][2])/2;
- }
- }
- if(M.Fill_In==2)
- {
- for(k=1;k<=M.Max_Fill;k++)
- {
- r0=M.lut[k+16].r=M.Fill_Color_RGB[k][0];
- g0=M.lut[k+16].g=M.Fill_Color_RGB[k][1];
- b0=M.lut[k+16].b=M.Fill_Color_RGB[k][2];
- mindist=16777216;
- for(m=0;m<MAX_COLORS;m++)
- {
- for(n=m;n<MAX_COLORS;n++)
- {
- r=(long)(M.Color_Val[m][0]+M.Color_Val[n][0])/2;
- g=(long)(M.Color_Val[m][1]+M.Color_Val[n][1])/2;
- b=(long)(M.Color_Val[m][2]+M.Color_Val[n][2])/2;
- dist=(r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
- if(dist<mindist&&m!=M.Back&&n!=M.Back)
- {
- mindist=dist;
- M.Fill_Color[k][0]=c1=m;
- M.Fill_Color[k][1]=c2=n;
- }
- }
- }
- if(Fpout&&iop!=1)
- fprintf(Fpout," %8s %8s %s\n",
- M.Color_Name[c1],M.Color_Name[c2],M.Fill_Name[k]);
- }
- }
- if(M.Fill_In==3)
- {
- for(k=1;k<=M.Max_Fill;k++)
- {
- i=M.Fill_Color_IHS[k][0];
- h=M.Fill_Color_IHS[k][1];
- s=M.Fill_Color_IHS[k][2];
- if(Fpout&&iop!=1)
- fprintf(Fpout,"%3d %5.2f %3d %5.2f ",k,i,h,s);
- for(j=0;j<3;j++)
- {
- rgb[j]=MaxHues[h][j];
- rgb[j]+=(255.0-rgb[j])*(1.0-s);
- rgb[j]*=i;
- if(rgb[j]<0.0)
- rgb[j]=0.0;
- if(rgb[j]>255.0)
- rgb[j]=255.0;
- if(Fpout&&iop!=1)
- fprintf(Fpout,"%3.0f ",rgb[j]);
- }
- r0=M.lut[k+16].r=rgb[0];
- g0=M.lut[k+16].g=rgb[1];
- b0=M.lut[k+16].b=rgb[2];
- mindist=16777216;
- for(m=0;m<MAX_COLORS;m++)
- {
- for(n=m;n<MAX_COLORS;n++)
- {
- r=(long)(M.Color_Val[m][0]+M.Color_Val[n][0])/2;
- g=(long)(M.Color_Val[m][1]+M.Color_Val[n][1])/2;
- b=(long)(M.Color_Val[m][2]+M.Color_Val[n][2])/2;
- dist=(r-r0)*(r-r0)+(g-g0)*(g-g0)+(b-b0)*(b-b0);
- if(dist<mindist&&m!=M.Back&&n!=M.Back)
- {
- mindist=dist;
- M.Fill_Color[k][0]=c1=m;
- M.Fill_Color[k][1]=c2=n;
- }
- }
- }
- if(Fpout&&iop!=1)
- fprintf(Fpout," %8s %8s %s\n",
- M.Color_Name[c1],M.Color_Name[c2],M.Fill_Name[k]);
- }
- }
- for(k=0;k<256;k++)
- {
- if(M.lut[k].r>128||M.lut[k].g>128||M.lut[k].b>160)
- M.Comp_Color[k]=M.Black;
- else
- M.Comp_Color[k]=M.White;
- }
- }
- WritePalette(M.lut);
- }
-
-
-